[Mesa-dev] [PATCH 2/2] tgsi/lowering: add support to lower CEIL
Roland Scheidegger
sroland at vmware.com
Wed Apr 13 22:18:33 UTC 2016
Am 13.04.2016 um 22:51 schrieb Christian Gmeiner:
> Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
> ---
> src/gallium/auxiliary/tgsi/tgsi_lowering.c | 54 ++++++++++++++++++++++++++++++
> src/gallium/auxiliary/tgsi/tgsi_lowering.h | 1 +
> 2 files changed, 55 insertions(+)
>
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_lowering.c b/src/gallium/auxiliary/tgsi/tgsi_lowering.c
> index cd5bdc2..54536d1 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_lowering.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_lowering.c
> @@ -302,6 +302,50 @@ transform_flr(struct tgsi_transform_context *tctx,
> }
> }
>
> +/* CEIL - Ceiling
> + *
> + * dst.x = \lceil src.x\rceil
> + * dst.y = \lceil src.y\rceil
> + * dst.z = \lceil src.z\rceil
> + * dst.w = \lceil src.w\rceil
> + *
> + * ; needs: 1 tmp
> + * FRC tmpA, src
> + * ADD dst, src, tmpA
The math here really doesn't add up. Might have more luck when throwing
in a negation first (FRC tmpA, -src).
Roland
> + */
> +#define CEIL_GROW (NINST(1) + NINST(2) - OINST(1))
> +#define CEIL_TMP 1
> +static void
> +transform_ceil(struct tgsi_transform_context *tctx,
> + struct tgsi_full_instruction *inst)
> +{
> + struct tgsi_lowering_context *ctx = tgsi_lowering_context(tctx);
> + struct tgsi_full_dst_register *dst = &inst->Dst[0];
> + struct tgsi_full_src_register *src = &inst->Src[0];
> + struct tgsi_full_instruction new_inst;
> +
> + if (dst->Register.WriteMask & TGSI_WRITEMASK_XYZW) {
> + /* FRC tmpA, src */
> + new_inst = tgsi_default_full_instruction();
> + new_inst.Instruction.Opcode = TGSI_OPCODE_FRC;
> + new_inst.Instruction.NumDstRegs = 1;
> + reg_dst(&new_inst.Dst[0], &ctx->tmp[A].dst, TGSI_WRITEMASK_XYZW);
> + new_inst.Instruction.NumSrcRegs = 1;
> + reg_src(&new_inst.Src[0], src, SWIZ(X, Y, Z, W));
> + tctx->emit_instruction(tctx, &new_inst);
> +
> + /* ADD dst, src, tmpA */
> + new_inst = tgsi_default_full_instruction();
> + new_inst.Instruction.Opcode = TGSI_OPCODE_ADD;
> + new_inst.Instruction.NumDstRegs = 1;
> + reg_dst(&new_inst.Dst[0], dst, TGSI_WRITEMASK_XYZW);
> + new_inst.Instruction.NumSrcRegs = 2;
> + reg_src(&new_inst.Src[0], src, SWIZ(X, Y, Z, W));
> + reg_src(&new_inst.Src[1], &ctx->tmp[A].src, SWIZ(X, Y, Z, W));
> + tctx->emit_instruction(tctx, &new_inst);
> + }
> +}
> +
> /* XPD - Cross Product
> * dst.x = src0.y \times src1.z - src1.y \times src0.z
> * dst.y = src0.z \times src1.x - src1.z \times src0.x
> @@ -1385,6 +1429,11 @@ transform_instr(struct tgsi_transform_context *tctx,
> goto skip;
> transform_flr(tctx, inst);
> break;
> + case TGSI_OPCODE_CEIL:
> + if (!ctx->config->lower_CEIL)
> + goto skip;
> + transform_ceil(tctx, inst);
> + break;
> case TGSI_OPCODE_XPD:
> if (!ctx->config->lower_XPD)
> goto skip;
> @@ -1510,6 +1559,7 @@ tgsi_transform_lowering(const struct tgsi_lowering_config *config,
> /* if there are no instructions to lower, then we are done: */
> if (!(OPCS(DST) ||
> OPCS(FLR) ||
> + OPCS(CEIL) ||
> OPCS(XPD) ||
> OPCS(SCS) ||
> OPCS(LRP) ||
> @@ -1543,6 +1593,10 @@ tgsi_transform_lowering(const struct tgsi_lowering_config *config,
> newlen += FLR_GROW * OPCS(FLR);
> numtmp = MAX2(numtmp, FLR_TMP);
> }
> + if (OPCS(CEIL)) {
> + newlen += CEIL_GROW * OPCS(CEIL);
> + numtmp = MAX2(numtmp, CEIL_TMP);
> + }
> if (OPCS(XPD)) {
> newlen += XPD_GROW * OPCS(XPD);
> numtmp = MAX2(numtmp, XPD_TMP);
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_lowering.h b/src/gallium/auxiliary/tgsi/tgsi_lowering.h
> index 803f84e..f2d02a4 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_lowering.h
> +++ b/src/gallium/auxiliary/tgsi/tgsi_lowering.h
> @@ -56,6 +56,7 @@ struct tgsi_lowering_config
> */
> unsigned lower_DST:1;
> unsigned lower_FLR:1;
> + unsigned lower_CEIL:1;
> unsigned lower_XPD:1;
> unsigned lower_SCS:1;
> unsigned lower_LRP:1;
>
More information about the mesa-dev
mailing list