gallium/vl: Simplify the matrix filter fragment shader
authorThomas Hellstrom <thellstrom@vmware.com>
Fri, 23 Sep 2016 11:23:05 +0000 (13:23 +0200)
committerThomas Hellstrom <thellstrom@vmware.com>
Wed, 22 Feb 2017 09:22:17 +0000 (10:22 +0100)
It looks like it was partly copied from the median filter fragment shader
and unnecessesarily saved a lot of temporary values.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/auxiliary/vl/vl_matrix_filter.c

index 11ec8161f4de9207985b59df6de42b60f05203af..b498d1f1db202d0b4915cef9143dea53c2b892f6 100644 (file)
@@ -81,15 +81,13 @@ create_frag_shader(struct vl_matrix_filter *filter, unsigned num_offsets,
    struct ureg_program *shader;
    struct ureg_src i_vtex;
    struct ureg_src sampler;
-   struct ureg_dst *t_array = MALLOC(sizeof(struct ureg_dst) * num_offsets);
+   struct ureg_dst tmp;
    struct ureg_dst t_sum;
    struct ureg_dst o_fragment;
-   bool first;
    unsigned i;
 
    shader = ureg_create(PIPE_SHADER_FRAGMENT);
    if (!shader) {
-      FREE(t_array);
       return NULL;
    }
 
@@ -101,54 +99,32 @@ create_frag_shader(struct vl_matrix_filter *filter, unsigned num_offsets,
                           TGSI_RETURN_TYPE_FLOAT,
                           TGSI_RETURN_TYPE_FLOAT);
 
-   for (i = 0; i < num_offsets; ++i)
-      if (matrix_values[i] != 0.0f)
-         t_array[i] = ureg_DECL_temporary(shader);
-
+   tmp = ureg_DECL_temporary(shader);
+   t_sum = ureg_DECL_temporary(shader);
    o_fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
 
-   /*
-    * t_array[0..*] = vtex + offset[0..*]
-    * t_array[0..*] = tex(t_array[0..*], sampler)
-    * o_fragment = sum(t_array[0..*] * matrix_values[0..*])
-    */
-
+   ureg_MOV(shader, t_sum, ureg_imm1f(shader, 0.0f));
    for (i = 0; i < num_offsets; ++i) {
-      if (matrix_values[i] != 0.0f && !is_vec_zero(offsets[i])) {
-         ureg_ADD(shader, ureg_writemask(t_array[i], TGSI_WRITEMASK_XY),
+      if (matrix_values[i] == 0.0f)
+         continue;
+
+      if (!is_vec_zero(offsets[i])) {
+         ureg_ADD(shader, ureg_writemask(tmp, TGSI_WRITEMASK_XY),
                   i_vtex, ureg_imm2f(shader, offsets[i].x, offsets[i].y));
-         ureg_MOV(shader, ureg_writemask(t_array[i], TGSI_WRITEMASK_ZW),
+         ureg_MOV(shader, ureg_writemask(tmp, TGSI_WRITEMASK_ZW),
                   ureg_imm1f(shader, 0.0f));
+         ureg_TEX(shader, tmp, TGSI_TEXTURE_2D, ureg_src(tmp), sampler);
+      } else {
+         ureg_TEX(shader, tmp, TGSI_TEXTURE_2D, i_vtex, sampler);
       }
+      ureg_MAD(shader, t_sum, ureg_src(tmp), ureg_imm1f(shader, matrix_values[i]),
+               ureg_src(t_sum));
    }
 
-   for (i = 0; i < num_offsets; ++i) {
-      if (matrix_values[i] != 0.0f) {
-         struct ureg_src src = is_vec_zero(offsets[i]) ? i_vtex : ureg_src(t_array[i]);
-         ureg_TEX(shader, t_array[i], TGSI_TEXTURE_2D, src, sampler);
-      }
-   }
-
-   for (i = 0, first = true; i < num_offsets; ++i) {
-      if (matrix_values[i] != 0.0f) {
-         if (first) {
-            t_sum = t_array[i];
-            ureg_MUL(shader, t_sum, ureg_src(t_array[i]),
-                     ureg_imm1f(shader, matrix_values[i]));
-            first = false;
-         } else
-            ureg_MAD(shader, t_sum, ureg_src(t_array[i]),
-                     ureg_imm1f(shader, matrix_values[i]), ureg_src(t_sum));
-      }
-   }
-   if (first)
-      ureg_MOV(shader, o_fragment, ureg_imm1f(shader, 0.0f));
-   else
-      ureg_MOV(shader, o_fragment, ureg_src(t_sum));
+   ureg_MOV(shader, o_fragment, ureg_src(t_sum));
 
    ureg_END(shader);
 
-   FREE(t_array);
    return ureg_create_shader_and_destroy(shader, filter->pipe);
 }