[Mesa-dev] [PATCH 1/2] i965/fs: Simulate MAD opcode with gen<6

Matt Turner mattst88 at gmail.com
Tue May 6 09:37:51 PDT 2014


On Tue, May 6, 2014 at 3:53 AM, Juha-Pekka Heikkila
<juhapekka.heikkila at gmail.com> wrote:
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> index d2dc5fa..22ca528 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> @@ -293,10 +293,6 @@ fs_visitor::try_emit_saturate(ir_expression *ir)
>  bool
>  fs_visitor::try_emit_mad(ir_expression *ir)
>  {
> -   /* 3-src instructions were introduced in gen6. */
> -   if (brw->gen < 6)
> -      return false;
> -
>     /* MAD can only handle floating-point data. */
>     if (ir->type != glsl_type::float_type)
>        return false;
> @@ -327,7 +323,16 @@ fs_visitor::try_emit_mad(ir_expression *ir)
>     fs_reg src2 = this->result;
>
>     this->result = fs_reg(this, ir->type);
> -   emit(BRW_OPCODE_MAD, this->result, src0, src1, src2);
> +
> +   /* 3-src instructions were introduced in gen6. */
> +   if (brw->gen < 6) {
> +      fs_reg temp = fs_reg(this, glsl_type::float_type);
> +
> +      emit(MUL(temp, src1, src2));
> +      emit(ADD(this->result, src0, temp));
> +   } else {
> +      emit(BRW_OPCODE_MAD, this->result, src0, src1, src2);
> +   }
>
>     return true;
>  }
> --
> 1.8.1.2

try_emit_mad is called every time we visit an add-expression, and on
platforms that don't have MAD it fails and the compiler generates
standard code for the expression tree.

So, if your expression tree was a a multiply-add the compiler will
generate a multiply and an add instruction. Adding code to make
try_emit_mad do that doesn't actually change anything.

I've made a branch that uses the LINE instruction to perform
multiply-adds when the arguments are immediates. Minus the shader size
explosion in unigine tropics, it seems to be a pretty nice
improvement. But the problem with unigine will have to be sorted out
before it can be committed.

Maybe you'd be interested in taking a look at that?

See https://bugs.freedesktop.org/show_bug.cgi?id=77544


More information about the mesa-dev mailing list