Skip to content

Commit

Permalink
shaders/sampling: fill the lut padding
Browse files Browse the repository at this point in the history
This ensures that we don't interpolate lut values with garbage values
when row_size is not multiple of 4. Avoid UB that produces incorrect
values.

This commit fixes the fast path of orthogonal scaling.

Fixes: mpv-player/mpv#13998
  • Loading branch information
kasper93 committed Oct 15, 2024
1 parent 9e16c86 commit 118d810
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shaders/sampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,16 @@ static void fill_ortho_lut(void *data, const struct sh_lut_params *params)
const float *weights = filt->weights + n * filt->row_stride;
float *row = (float *) data + n * filt->row_stride;
pl_assert(filt->row_size % 2 == 0);
for (int i = 0; i < filt->row_size; i += 2) {
int i = 0;
for (; i < filt->row_size; i += 2) {
const float w0 = weights[i], w1 = weights[i+1];
assert(w0 + w1 >= 0.0f);
row[i] = w0 + w1;
row[i+1] = w1 / (w0 + w1);
}
pl_assert(filt->params.row_stride_align == 4); // always 4 components
for (; i < filt->row_stride; i++)
row[i] = i >= 4 ? row[i - 4] : 0;
}
} else {
size_t entries = SCALER_LUT_SIZE * filt->row_stride;
Expand Down

0 comments on commit 118d810

Please sign in to comment.