From: Thomas Hellstrom Date: Fri, 23 Sep 2016 11:23:05 +0000 (+0200) Subject: gallium/vl: Simplify the matrix filter fragment shader X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ccc8720cf7d3cb538bde1cd158755bde2e36eefd;p=mesa.git gallium/vl: Simplify the matrix filter fragment shader 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 Reviewed-by: Brian Paul Reviewed-by: Christian König --- diff --git a/src/gallium/auxiliary/vl/vl_matrix_filter.c b/src/gallium/auxiliary/vl/vl_matrix_filter.c index 11ec8161f4d..b498d1f1db2 100644 --- a/src/gallium/auxiliary/vl/vl_matrix_filter.c +++ b/src/gallium/auxiliary/vl/vl_matrix_filter.c @@ -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); }