summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Hellstrom <[email protected]>2016-09-23 13:23:05 +0200
committerThomas Hellstrom <[email protected]>2017-02-22 10:22:17 +0100
commitccc8720cf7d3cb538bde1cd158755bde2e36eefd (patch)
tree2ddf25d979bd1a63b57225b2bda0006cf592c332 /src
parentf1e5dfbe3c8951a6c8acf41bf5e6c2d090098b2c (diff)
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 <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Christian König <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/vl/vl_matrix_filter.c56
1 files changed, 16 insertions, 40 deletions
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);
}