[Mesa-dev] [PATCH 2/2] gallium/ttn: add TXQ support

Rob Clark robdclark at gmail.com
Thu Apr 9 13:00:58 PDT 2015


On Thu, Apr 9, 2015 at 3:43 PM, Rob Clark <robdclark at gmail.com> wrote:
> From: Rob Clark <robclark at freedesktop.org>
>
> Split out from ttn_tex() since it is kind of a weird instruction that
> maps to two NIR opcodes, and it was cleaner this way.
>

as Ilia pointed out on IRC, query_levels should have no src args..
I've fixed that locally (but figured I'd wait a bit to see if there
are any other comments before I resend)

BR,
-R

> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> ---
>  src/gallium/auxiliary/nir/tgsi_to_nir.c | 61 ++++++++++++++++++++++++++++-----
>  1 file changed, 53 insertions(+), 8 deletions(-)
>
> diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c
> index c2b823c..9e0ffc2 100644
> --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
> +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
> @@ -1018,13 +1018,11 @@ ttn_tex(struct ttn_compile *c, nir_alu_dest dest, nir_ssa_def **src)
>
>     unsigned src_number = 0;
>
> -   if (tgsi_inst->Instruction.Opcode != TGSI_OPCODE_TXQ) {
> -      instr->src[src_number].src =
> -         nir_src_for_ssa(nir_swizzle(b, src[0], SWIZ(X, Y, Z, W),
> -                                     instr->coord_components, false));
> -      instr->src[src_number].src_type = nir_tex_src_coord;
> -      src_number++;
> -   }
> +   instr->src[src_number].src =
> +      nir_src_for_ssa(nir_swizzle(b, src[0], SWIZ(X, Y, Z, W),
> +                                  instr->coord_components, false));
> +   instr->src[src_number].src_type = nir_tex_src_coord;
> +   src_number++;
>
>     if (tgsi_inst->Instruction.Opcode == TGSI_OPCODE_TXP) {
>        instr->src[src_number].src = nir_src_for_ssa(ttn_channel(b, src[0], W));
> @@ -1063,6 +1061,50 @@ ttn_tex(struct ttn_compile *c, nir_alu_dest dest, nir_ssa_def **src)
>     ttn_move_dest(b, dest, &instr->dest.ssa);
>  }
>
> +/* TGSI_OPCODE_TXQ is actually two distinct operations:
> + *
> + *     dst.x = texture\_width(unit, lod)
> + *     dst.y = texture\_height(unit, lod)
> + *     dst.z = texture\_depth(unit, lod)
> + *     dst.w = texture\_levels(unit)
> + *
> + * dst.xyz map to NIR txs opcode, and dst.w maps to query_levels
> + */
> +static void
> +ttn_txq(struct ttn_compile *c, nir_alu_dest dest, nir_ssa_def **src)
> +{
> +   nir_builder *b = &c->build;
> +   struct tgsi_full_instruction *tgsi_inst = &c->token->FullInstruction;
> +   nir_tex_instr *txs, *qlv;
> +
> +   txs = nir_tex_instr_create(b->shader, 1);
> +   txs->op = nir_texop_txs;
> +   setup_texture_info(txs, tgsi_inst->Texture.Texture);
> +
> +   qlv = nir_tex_instr_create(b->shader, 1);
> +   qlv->op = nir_texop_query_levels;
> +   setup_texture_info(qlv, tgsi_inst->Texture.Texture);
> +
> +   assert(tgsi_inst->Src[1].Register.File == TGSI_FILE_SAMPLER);
> +   txs->sampler_index = tgsi_inst->Src[1].Register.Index;
> +   qlv->sampler_index = tgsi_inst->Src[1].Register.Index;
> +
> +   /* only single src, the lod: */
> +   txs->src[0].src = nir_src_for_ssa(ttn_channel(b, src[0], X));
> +   txs->src[0].src_type = nir_tex_src_lod;
> +   qlv->src[0].src = nir_src_for_ssa(ttn_channel(b, src[0], X));
> +   qlv->src[0].src_type = nir_tex_src_lod;
> +
> +   nir_ssa_dest_init(&txs->instr, &txs->dest, 3, NULL);
> +   nir_instr_insert_after_cf_list(b->cf_node_list, &txs->instr);
> +
> +   nir_ssa_dest_init(&qlv->instr, &qlv->dest, 1, NULL);
> +   nir_instr_insert_after_cf_list(b->cf_node_list, &qlv->instr);
> +
> +   ttn_move_dest_masked(b, dest, &txs->dest.ssa, TGSI_WRITEMASK_XYZ);
> +   ttn_move_dest_masked(b, dest, &qlv->dest.ssa, TGSI_WRITEMASK_W);
> +}
> +
>  static const nir_op op_trans[TGSI_OPCODE_LAST] = {
>     [TGSI_OPCODE_ARL] = 0,
>     [TGSI_OPCODE_MOV] = nir_op_fmov,
> @@ -1386,7 +1428,6 @@ ttn_emit_instruction(struct ttn_compile *c)
>     case TGSI_OPCODE_TXL:
>     case TGSI_OPCODE_TXB:
>     case TGSI_OPCODE_TXD:
> -   case TGSI_OPCODE_TXQ:
>     case TGSI_OPCODE_TXL2:
>     case TGSI_OPCODE_TXB2:
>     case TGSI_OPCODE_TXQ_LZ:
> @@ -1395,6 +1436,10 @@ ttn_emit_instruction(struct ttn_compile *c)
>        ttn_tex(c, dest, src);
>        break;
>
> +   case TGSI_OPCODE_TXQ:
> +      ttn_txq(c, dest, src);
> +      break;
> +
>     case TGSI_OPCODE_NOP:
>        break;
>
> --
> 2.1.0
>


More information about the mesa-dev mailing list