[Mesa-dev] [PATCH] nir: Always print non-xyzw swizzles.

Ilia Mirkin imirkin at alum.mit.edu
Mon Sep 21 21:37:08 PDT 2015


On Tue, Sep 22, 2015 at 12:31 AM, Matt Turner <mattst88 at gmail.com> wrote:
> Previously we would not print a swizzle on ssa_52 when only its .x
> component is used (as seen in the definition of ssa_53):
>
>    vec3 ssa_52 = fadd ssa_51, ssa_51
>    vec1 ssa_53 = flog2 ssa_52
>    vec1 ssa_54 = flog2 ssa_52.y
>    vec1 ssa_55 = flog2 ssa_52.z
>
> But this makes the interpretation of the RHS of the definition difficult
> to understand and dependent on the size of the LHS. Just print swizzles
> when they are not .xyzw (which is only possible on vec4 uses), so the
> previous example is now printed as:
>
>    vec3 ssa_52 = fadd ssa_51.xyz, ssa_51.xyz

IMHO if ssa_51 is a vec3, this makes sense without the .xyz. I'd
change the condition to print the identity swizzle only if source size
!= output size, not sure if that's easy to do though.

>    vec1 ssa_53 = flog2 ssa_52.x
>    vec1 ssa_54 = flog2 ssa_52.y
>    vec1 ssa_55 = flog2 ssa_52.z
> ---
>  src/glsl/nir/nir_print.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
> index a19aa8b..f72c062 100644
> --- a/src/glsl/nir/nir_print.c
> +++ b/src/glsl/nir/nir_print.c
> @@ -158,17 +158,20 @@ print_alu_src(nir_alu_instr *instr, unsigned src, print_state *state)
>     print_src(&instr->src[src].src, state);
>
>     bool print_swizzle = false;
> +   unsigned used_channels = 0;
>     for (unsigned i = 0; i < 4; i++) {
>        if (!nir_alu_instr_channel_used(instr, src, i))
>           continue;
>
> +      used_channels++;
> +
>        if (instr->src[src].swizzle[i] != i) {
>           print_swizzle = true;
>           break;
>        }
>     }
>
> -   if (print_swizzle) {
> +   if (print_swizzle || used_channels != 4) {
>        fprintf(fp, ".");
>        for (unsigned i = 0; i < 4; i++) {
>           if (!nir_alu_instr_channel_used(instr, src, i))
> --
> 2.4.6
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list