OSDN Git Service

nir: Fix output swizzle in get_mul_for_src
authorIago Toral Quiroga <itoral@igalia.com>
Thu, 28 May 2015 07:06:33 +0000 (09:06 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Thu, 28 May 2015 16:25:37 +0000 (18:25 +0200)
When we compute the output swizzle we want to consider the number of
components in the add operation. So far we were using the writemask
of the multiplication for this instead, which is not correct.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/glsl/nir/nir_opt_peephole_ffma.c

index b430eac..798506b 100644 (file)
@@ -73,7 +73,8 @@ are_all_uses_fadd(nir_ssa_def *def)
 }
 
 static nir_alu_instr *
-get_mul_for_src(nir_alu_src *src, uint8_t swizzle[4], bool *negate, bool *abs)
+get_mul_for_src(nir_alu_src *src, int num_components,
+                uint8_t swizzle[4], bool *negate, bool *abs)
 {
    assert(src->src.is_ssa && !src->abs && !src->negate);
 
@@ -85,16 +86,16 @@ get_mul_for_src(nir_alu_src *src, uint8_t swizzle[4], bool *negate, bool *abs)
    switch (alu->op) {
    case nir_op_imov:
    case nir_op_fmov:
-      alu = get_mul_for_src(&alu->src[0], swizzle, negate, abs);
+      alu = get_mul_for_src(&alu->src[0], num_components, swizzle, negate, abs);
       break;
 
    case nir_op_fneg:
-      alu = get_mul_for_src(&alu->src[0], swizzle, negate, abs);
+      alu = get_mul_for_src(&alu->src[0], num_components, swizzle, negate, abs);
       *negate = !*negate;
       break;
 
    case nir_op_fabs:
-      alu = get_mul_for_src(&alu->src[0], swizzle, negate, abs);
+      alu = get_mul_for_src(&alu->src[0], num_components, swizzle, negate, abs);
       *negate = false;
       *abs = true;
       break;
@@ -115,12 +116,8 @@ get_mul_for_src(nir_alu_src *src, uint8_t swizzle[4], bool *negate, bool *abs)
    if (!alu)
       return NULL;
 
-   for (unsigned i = 0; i < 4; i++) {
-      if (!(alu->dest.write_mask & (1 << i)))
-         break;
-
+   for (unsigned i = 0; i < num_components; i++)
       swizzle[i] = swizzle[src->swizzle[i]];
-   }
 
    return alu;
 }
@@ -160,7 +157,9 @@ nir_opt_peephole_ffma_block(nir_block *block, void *void_state)
          negate = false;
          abs = false;
 
-         mul = get_mul_for_src(&add->src[add_mul_src], swizzle, &negate, &abs);
+         mul = get_mul_for_src(&add->src[add_mul_src],
+                               add->dest.dest.ssa.num_components,
+                               swizzle, &negate, &abs);
 
          if (mul != NULL)
             break;