[Mesa-dev] [PATCH 006/133] nir: add a printer

Eric Anholt eric at anholt.net
Wed Dec 17 22:22:22 PST 2014


Jason Ekstrand <jason at jlekstrand.net> writes:

> From: Connor Abbott <connor.abbott at intel.com>
>
> This is similar to ir_print_visitor.cpp.


> +static void
> +print_alu_src(nir_alu_src *src, FILE *fp)
> +{
> +   if (src->negate)
> +      fprintf(fp, "-");
> +   if (src->abs)
> +      fprintf(fp, "abs(");
> +
> +   print_src(&src->src, fp);
> +
> +   if (src->swizzle[0] != 0 ||
> +       src->swizzle[1] != 1 ||
> +       src->swizzle[2] != 2 ||
> +       src->swizzle[3] != 3) {
> +      fprintf(fp, ".");
> +      for (unsigned i = 0; i < 4; i++)
> +         fprintf(fp, "%c", "xyzw"[src->swizzle[i]]);

Not necessary in the review process, but I've been thinking it would be
nice to use nir_alu_instr_channel_used() to skip printing unused swizzle
characters (replacing it with '_' maybe).  It would usually help me when
I'm reading shader dumps.

> +static void
> +print_alu_instr(nir_alu_instr *instr, FILE *fp)
> +{
> +   if (instr->has_predicate) {
> +      fprintf(fp, "(");
> +      print_src(&instr->predicate, fp);
> +      fprintf(fp, ") ");
> +   }
> +
> +   print_alu_dest(&instr->dest, fp);
> +
> +   fprintf(fp, " = %s", nir_op_infos[instr->op].name);
> +   if (instr->dest.saturate)
> +      fprintf(fp, ".sat");
> +   fprintf(fp, " ");
> +
> +   bool first = true;
> +   for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
> +      if (!first)
> +         fprintf(fp, ", ");

replace !first with i != 0?

(optional style change throughout the file)

> +      print_alu_src(&instr->src[i], fp);
> +
> +      first = false;
> +   }
> +}


> +
> +   bool offset_nonzero = false;
> +   for (unsigned i = 0; i < 4; i++)
> +      if (instr->const_offset[i] != 0) {
> +         offset_nonzero = true;
> +         break;
> +      }
> +
> +   if (offset_nonzero) {
> +      fprintf(fp, "[%i %i %i %i] (offset), ",
> +              instr->const_offset[0], instr->const_offset[1],
> +              instr->const_offset[2], instr->const_offset[3]);
> +   }

cleanup: just replace the "offset_nonzero = true;" statement with this
fprintf?  (also, {} around long multi-line blocks, please, even if
they're a single statement).

Other then these little cleanups,

Reviewed-by: Eric Anholt <eric at anholt.net>

I've got a patch in my series to make a single-instruction printer,
which is really nice to have for debugging in various "unreachable"
default blocks of switch statements and nir_validate and things.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141217/c3e83ca8/attachment.sig>


More information about the mesa-dev mailing list