[Mesa-dev] [PATCH] glsl: Drop constant 0.0 components from dot products.
Kenneth Graunke
kenneth at whitecape.org
Wed Oct 29 16:15:48 PDT 2014
On Thursday, October 23, 2014 04:19:19 PM Matt Turner wrote:
> Helps a small number of vertex shaders in the games Dungeon Defenders
> and Shank, as well as an internal benchmark.
>
> instructions in affected programs: 2801 -> 2719 (-2.93%)
> ---
> src/glsl/opt_algebraic.cpp | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
> index 0cdb8ec..6976ee7 100644
> --- a/src/glsl/opt_algebraic.cpp
> +++ b/src/glsl/opt_algebraic.cpp
> @@ -553,6 +553,31 @@ ir_algebraic_visitor::handle_expression(ir_expression
*ir)
> }
> return new(mem_ctx) ir_swizzle(ir->operands[0], component, 0, 0, 0, 1);
> }
> +
> + for (int i = 0; i < 2; i++) {
> + if (!op_const[i])
> + continue;
> +
> + unsigned components[4] = { 0 }, count = 0;
> +
> + for (unsigned c = 0; c < op_const[i]->type->vector_elements; c++)
{
> + if (op_const[i]->value.f[c] == 0.0)
> + continue;
> +
/* Store which channels have non-zero values. */
> + components[count] = c;
> + count++;
> + }
> +
/* No channels had zero values; bail. */
> + if (count >= op_const[i]->type->vector_elements)
> + break;
/* Swizzle both operands to remove the channels that were zero. */
> + return new(mem_ctx)
> + ir_expression(ir_binop_dot, glsl_type::float_type,
> + new(mem_ctx) ir_swizzle(ir->operands[0],
> + components, count),
> + new(mem_ctx) ir_swizzle(ir->operands[1],
> + components, count));
> + }
> break;
>
> case ir_binop_less:
With or without the comments,
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141029/14ba2523/attachment.sig>
More information about the mesa-dev
mailing list