gallium: avoid using float based conditions in loops

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12996>
This commit is contained in:
Filip Gawin
2021-08-16 22:41:24 +02:00
committed by Marge Bot
parent 5650d67242
commit 1a03788195
2 changed files with 57 additions and 28 deletions
+13 -6
View File
@@ -138,8 +138,12 @@ vl_matrix_filter_init(struct vl_matrix_filter *filter, struct pipe_context *pipe
struct pipe_blend_state blend;
struct pipe_sampler_state sampler;
struct pipe_vertex_element ve;
struct vertex2f *offsets, v, sizes;
struct vertex2f *offsets;
unsigned i, num_offsets = matrix_width * matrix_height;
int x;
int y;
int size_x;
int size_y;
assert(filter && pipe);
assert(video_width && video_height);
@@ -202,12 +206,15 @@ vl_matrix_filter_init(struct vl_matrix_filter *filter, struct pipe_context *pipe
if (!offsets)
goto error_offsets;
sizes.x = (float)(matrix_width - 1) / 2.0f;
sizes.y = (float)(matrix_height - 1) / 2.0f;
size_x = (matrix_width - 1) / 2;
size_y = (matrix_height - 1) / 2;
for (v.x = -sizes.x, i = 0; v.x <= sizes.x; v.x += 1.0f)
for (v.y = -sizes.y; v.y <= sizes.y; v.y += 1.0f)
offsets[i++] = v;
for (x = -size_x, i = 0; x <= size_x; x++)
for (y = -size_y; y <= size_y; y++) {
offsets[i].x = x;
offsets[i].y = y;
i++;
}
for (i = 0; i < num_offsets; ++i) {
offsets[i].x /= video_width;
+44 -22
View File
@@ -165,7 +165,8 @@ generate_offsets(enum vl_median_filter_shape shape, unsigned size,
{
unsigned i = 0;
int half_size;
struct vertex2f v;
int x;
int y;
assert(offsets && num_offsets);
@@ -199,41 +200,62 @@ generate_offsets(enum vl_median_filter_shape shape, unsigned size,
switch(shape) {
case VL_MEDIAN_FILTER_BOX:
for (v.x = -half_size; v.x <= half_size; ++v.x)
for (v.y = -half_size; v.y <= half_size; ++v.y)
(*offsets)[i++] = v;
for (x = -half_size; x <= half_size; ++x)
for (y = -half_size; y <= half_size; ++y) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
break;
case VL_MEDIAN_FILTER_CROSS:
v.y = 0.0f;
for (v.x = -half_size; v.x <= half_size; ++v.x)
(*offsets)[i++] = v;
y = 0;
for (x = -half_size; x <= half_size; ++x) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
v.x = 0.0f;
for (v.y = -half_size; v.y <= half_size; ++v.y)
if (v.y != 0.0f)
(*offsets)[i++] = v;
x = 0;
for (y = -half_size; y <= half_size; ++y)
if (y != 0) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
break;
case VL_MEDIAN_FILTER_X:
for (v.x = v.y = -half_size; v.x <= half_size; ++v.x, ++v.y)
(*offsets)[i++] = v;
for (x = y = -half_size; x <= half_size; ++x, ++y) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
for (v.x = -half_size, v.y = half_size; v.x <= half_size; ++v.x, --v.y)
if (v.y != 0.0f)
(*offsets)[i++] = v;
for (x = -half_size, y = half_size; x <= half_size; ++x, --y)
if (y != 0) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
break;
case VL_MEDIAN_FILTER_HORIZONTAL:
v.y = 0.0f;
for (v.x = -half_size; v.x <= half_size; ++v.x)
(*offsets)[i++] = v;
y = 0;
for (x = -half_size; x <= half_size; ++x) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
break;
case VL_MEDIAN_FILTER_VERTICAL:
v.x = 0.0f;
for (v.y = -half_size; v.y <= half_size; ++v.y)
(*offsets)[i++] = v;
x = 0;
for (y = -half_size; y <= half_size; ++y) {
(*offsets)[i].x = x;
(*offsets)[i].y = y;
i++;
}
break;
}