[Mesa-dev] [PATCH] gallium: add double opcodes and TGSI execution (v4.1)

Ilia Mirkin imirkin at alum.mit.edu
Thu Feb 19 14:30:55 PST 2015


On Thu, Feb 19, 2015 at 4:53 PM, Dave Airlie <airlied at gmail.com> wrote:
> This patch adds support for a set of double opcodes
> to TGSI. It is an update of work done originally
> by Michal Krol on the gallium-double-opcodes branch.
>
> The opcodes have a hint where they came from in the
> header file.
>
> v2: add unsigned/int <-> double
> v2.1:  update docs.
>
> v3: add DRSQ (Glenn), fix review comments (Glenn).
>
> v4: drop DDIV
> v4.1: cleanups, fix some docs bugs, (Ilia)
>       rework store_dest and fetch_source fns. (Ilia)
>
> This is based on code by Michael Krol <michal at vmware.com>
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/gallium/auxiliary/tgsi/tgsi_exec.c     | 765 ++++++++++++++++++++++++++++-
>  src/gallium/auxiliary/tgsi/tgsi_info.c     |  24 +-
>  src/gallium/docs/source/tgsi.rst           |  92 +++-
>  src/gallium/include/pipe/p_shader_tokens.h |  26 +-
>  4 files changed, 877 insertions(+), 30 deletions(-)
>
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
> index 834568b..1deca82 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
> @@ -2980,6 +3274,355 @@ exec_endswitch(struct tgsi_exec_machine *mach)
>     UPDATE_EXEC_MASK(mach);
>  }
>
> +typedef void (* micro_dop)(union tgsi_double_channel *dst,
> +                           const union tgsi_double_channel *src);
> +
> +static void
> +fetch_double_channel(struct tgsi_exec_machine *mach,
> +                     union tgsi_double_channel *chan,
> +                     const struct tgsi_full_src_register *reg,
> +                     uint chan_0,
> +                     uint chan_1)
> +{
> +   union tgsi_exec_channel src[2];
> +   uint i;
> +
> +   fetch_source_d(mach, &src[0], reg, chan_0, TGSI_EXEC_DATA_UINT);
> +   fetch_source_d(mach, &src[1], reg, chan_1, TGSI_EXEC_DATA_UINT);
> +
> +   for (i = 0; i < TGSI_QUAD_SIZE; i++) {
> +      chan->u[i][0] = src[0].u[i];
> +      chan->u[i][1] = src[1].u[i];
> +   }
> +   if (reg->Register.Absolute) {
> +      micro_dabs(chan, chan);
> +   }
> +   if (reg->Register.Negate) {
> +      micro_dneg(chan, chan);
> +   }
> +

remove extra line.

> +}
> +
> +static void
> +store_double_channel(struct tgsi_exec_machine *mach,
> +                     const union tgsi_double_channel *chan,
> +                     const struct tgsi_full_dst_register *reg,
> +                     const struct tgsi_full_instruction *inst,
> +                     uint chan_0,
> +                     uint chan_1)
> +{
> +   union tgsi_exec_channel dst[2];
> +   uint i;
> +   union tgsi_double_channel temp;
> +   const uint execmask = mach->ExecMask;

add a blank line here

> +   switch (inst->Instruction.Saturate) {
> +   case TGSI_SAT_NONE:
> +      for (i = 0; i < TGSI_QUAD_SIZE; i++)
> +         if (execmask & (1 << i)) {
> +            dst[0].u[i] = chan->u[i][0];
> +            dst[1].u[i] = chan->u[i][1];
> +         }
> +      break;
> +
> +   case TGSI_SAT_ZERO_ONE:
> +      for (i = 0; i < TGSI_QUAD_SIZE; i++)
> +         if (execmask & (1 << i)) {
> +            if (chan->d[i] < 0.0f)

s/f//

> +               temp.d[i] = 0.0;
> +            else if (chan->d[i] > 1.0f)

s/f//

> +               temp.d[i] = 1.0;
> +            else
> +               temp.d[i] = chan->d[i];
> +
> +            dst[0].u[i] = temp.u[i][0];
> +            dst[1].u[i] = temp.u[i][1];
> +         }
> +      break;
> +
> +   case TGSI_SAT_MINUS_PLUS_ONE:
> +      for (i = 0; i < TGSI_QUAD_SIZE; i++)
> +         if (execmask & (1 << i)) {
> +            if (chan->d[i] < -1.0)
> +               temp.d[i] = -1.0;
> +            else if (chan->d[i] > 1.0)
> +               temp.d[i] = 1.0;
> +            else
> +               temp.d[i] = chan->d[i];
> +
> +            dst[0].u[i] = temp.u[i][0];
> +            dst[1].u[i] = temp.u[i][1];
> +         }
> +      break;
> +
> +   default:
> +      assert( 0 );
> +   }
> +
> +   store_dest_double(mach, &dst[0], reg, inst, chan_0, TGSI_EXEC_DATA_UINT);
> +   if (chan_1 != -1)
> +      store_dest_double(mach, &dst[1], reg, inst, chan_1, TGSI_EXEC_DATA_UINT);
> +}

[...]

> +static void
> +exec_dldexp(struct tgsi_exec_machine *mach,
> +            const struct tgsi_full_instruction *inst)
> +{
> +   union tgsi_double_channel src0;
> +   union tgsi_exec_channel src1;
> +   union tgsi_double_channel dst;
> +   int wmask;
> +
> +   wmask = inst->Dst[0].Register.WriteMask;
> +   if (wmask & TGSI_WRITEMASK_XY) {
> +

remove extra line

> +      fetch_double_channel(mach, &src0, &inst->Src[0], TGSI_CHAN_X, TGSI_CHAN_Y);
> +      fetch_source(mach, &src1, &inst->Src[1], TGSI_CHAN_X, TGSI_EXEC_DATA_INT);
> +      micro_dldexp(&dst, &src0, &src1);
> +      store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_X, TGSI_CHAN_Y);
> +   }
> +
> +   if (wmask & TGSI_WRITEMASK_ZW) {
> +      fetch_double_channel(mach, &src0, &inst->Src[0], TGSI_CHAN_Z, TGSI_CHAN_W);
> +      fetch_source(mach, &src1, &inst->Src[1], TGSI_CHAN_Z, TGSI_EXEC_DATA_INT);
> +      micro_dldexp(&dst, &src0, &src1);
> +      store_double_channel(mach, &dst, &inst->Dst[0], inst, TGSI_CHAN_Z, TGSI_CHAN_W);
> +   }
> +}

With the above trivial fixes, this is

Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>


More information about the mesa-dev mailing list