]> git.sesse.net Git - movit/blob - resample_effect.cpp
Revert the optimization of the bilinear weights.
[movit] / resample_effect.cpp
1 // Three-lobed Lanczos, the most common choice.
2 #define LANCZOS_RADIUS 3.0
3
4 #include <epoxy/gl.h>
5 #include <assert.h>
6 #include <limits.h>
7 #include <math.h>
8 #include <stdio.h>
9 #include <algorithm>
10 #include <Eigen/Sparse>
11 #include <Eigen/SparseQR>
12 #include <Eigen/OrderingMethods>
13
14 #include "effect_chain.h"
15 #include "effect_util.h"
16 #include "fp16.h"
17 #include "init.h"
18 #include "resample_effect.h"
19 #include "util.h"
20
21 using namespace Eigen;
22 using namespace std;
23
24 namespace movit {
25
26 namespace {
27
28 template<class T>
29 struct Tap {
30         T weight;
31         T pos;
32 };
33
34 float sinc(float x)
35 {
36         if (fabs(x) < 1e-6) {
37                 return 1.0f - fabs(x);
38         } else {
39                 return sin(x) / x;
40         }
41 }
42
43 float lanczos_weight(float x, float a)
44 {
45         if (fabs(x) > a) {
46                 return 0.0f;
47         } else {
48                 return sinc(M_PI * x) * sinc(M_PI * x / a);
49         }
50 }
51
52 // Euclid's algorithm, from Wikipedia.
53 unsigned gcd(unsigned a, unsigned b)
54 {
55         while (b != 0) {
56                 unsigned t = b;
57                 b = a % b;
58                 a = t;
59         }
60         return a;
61 }
62
63 template<class DestFloat>
64 unsigned combine_samples(const Tap<float> *src, Tap<DestFloat> *dst, unsigned src_size, unsigned num_src_samples, unsigned max_samples_saved)
65 {
66         unsigned num_samples_saved = 0;
67         for (unsigned i = 0, j = 0; i < num_src_samples; ++i, ++j) {
68                 // Copy the sample directly; it will be overwritten later if we can combine.
69                 if (dst != NULL) {
70                         dst[j].weight = convert_float<float, DestFloat>(src[i].weight);
71                         dst[j].pos = convert_float<float, DestFloat>(src[i].pos);
72                 }
73
74                 if (i == num_src_samples - 1) {
75                         // Last sample; cannot combine.
76                         continue;
77                 }
78                 assert(num_samples_saved <= max_samples_saved);
79                 if (num_samples_saved == max_samples_saved) {
80                         // We could maybe save more here, but other rows can't, so don't bother.
81                         continue;
82                 }
83
84                 float w1 = src[i].weight;
85                 float w2 = src[i + 1].weight;
86                 if (w1 * w2 < 0.0f) {
87                         // Differing signs; cannot combine.
88                         continue;
89                 }
90
91                 float pos1 = src[i].pos;
92                 float pos2 = src[i + 1].pos;
93                 assert(pos2 > pos1);
94
95                 fp16_int_t pos, total_weight;
96                 float sum_sq_error;
97                 combine_two_samples(w1, w2, pos1, pos2, src_size, &pos, &total_weight, &sum_sq_error);
98
99                 // If the interpolation error is larger than that of about sqrt(2) of
100                 // a level at 8-bit precision, don't combine. (You'd think 1.0 was enough,
101                 // but since the artifacts are not really random, they can get quite
102                 // visible. On the other hand, going to 0.25f, I can see no change at
103                 // all with 8-bit output, so it would not seem to be worth it.)
104                 if (sum_sq_error > 0.5f / (255.0f * 255.0f)) {
105                         continue;
106                 }
107
108                 // OK, we can combine this and the next sample.
109                 if (dst != NULL) {
110                         dst[j].weight = total_weight;
111                         dst[j].pos = pos;
112                 }
113
114                 ++i;  // Skip the next sample.
115                 ++num_samples_saved;
116         }
117         return num_samples_saved;
118 }
119
120 // Normalize so that the sum becomes one. Note that we do it twice;
121 // this sometimes helps a tiny little bit when we have many samples.
122 template<class T>
123 void normalize_sum(Tap<T>* vals, unsigned num)
124 {
125         for (int normalize_pass = 0; normalize_pass < 2; ++normalize_pass) {
126                 double sum = 0.0;
127                 for (unsigned i = 0; i < num; ++i) {
128                         sum += to_fp64(vals[i].weight);
129                 }
130                 for (unsigned i = 0; i < num; ++i) {
131                         vals[i].weight = from_fp64<T>(to_fp64(vals[i].weight) / sum);
132                 }
133         }
134 }
135
136 // Make use of the bilinear filtering in the GPU to reduce the number of samples
137 // we need to make. This is a bit more complex than BlurEffect since we cannot combine
138 // two neighboring samples if their weights have differing signs, so we first need to
139 // figure out the maximum number of samples. Then, we downconvert all the weights to
140 // that number -- we could have gone for a variable-length system, but this is simpler,
141 // and the gains would probably be offset by the extra cost of checking when to stop.
142 //
143 // The greedy strategy for combining samples is optimal.
144 template<class DestFloat>
145 unsigned combine_many_samples(const Tap<float> *weights, unsigned src_size, unsigned src_samples, unsigned dst_samples, Tap<DestFloat> **bilinear_weights)
146 {
147         int src_bilinear_samples = 0;
148         for (unsigned y = 0; y < dst_samples; ++y) {
149                 unsigned num_samples_saved = combine_samples<DestFloat>(weights + y * src_samples, NULL, src_size, src_samples, UINT_MAX);
150                 src_bilinear_samples = max<int>(src_bilinear_samples, src_samples - num_samples_saved);
151         }
152
153         // Now that we know the right width, actually combine the samples.
154         *bilinear_weights = new Tap<DestFloat>[dst_samples * src_bilinear_samples];
155         for (unsigned y = 0; y < dst_samples; ++y) {
156                 Tap<DestFloat> *bilinear_weights_ptr = *bilinear_weights + y * src_bilinear_samples;
157                 unsigned num_samples_saved = combine_samples(
158                         weights + y * src_samples,
159                         bilinear_weights_ptr,
160                         src_size,
161                         src_samples,
162                         src_samples - src_bilinear_samples);
163                 assert(int(src_samples) - int(num_samples_saved) == src_bilinear_samples);
164                 normalize_sum(bilinear_weights_ptr, src_bilinear_samples);
165         }
166         return src_bilinear_samples;
167 }
168
169 // Compute the sum of squared errors between the ideal weights (which are
170 // assumed to fall exactly on pixel centers) and the weights that result
171 // from sampling at <bilinear_weights>. The primary reason for the difference
172 // is inaccuracy in the sampling positions, both due to limited precision
173 // in storing them (already inherent in sending them in as fp16_int_t)
174 // and in subtexel sampling precision (which we calculate in this function).
175 template<class T>
176 double compute_sum_sq_error(const Tap<float>* weights, unsigned num_weights,
177                             const Tap<T>* bilinear_weights, unsigned num_bilinear_weights,
178                             unsigned size)
179 {
180         // Find the effective range of the bilinear-optimized kernel.
181         // Due to rounding of the positions, this is not necessarily the same
182         // as the intended range (ie., the range of the original weights).
183         int lower_pos = int(floor(to_fp64(bilinear_weights[0].pos) * size - 0.5));
184         int upper_pos = int(ceil(to_fp64(bilinear_weights[num_bilinear_weights - 1].pos) * size - 0.5)) + 2;
185         lower_pos = min<int>(lower_pos, lrintf(weights[0].pos * size - 0.5));
186         upper_pos = max<int>(upper_pos, lrintf(weights[num_weights - 1].pos * size - 0.5));
187
188         float* effective_weights = new float[upper_pos - lower_pos];
189         for (int i = 0; i < upper_pos - lower_pos; ++i) {
190                 effective_weights[i] = 0.0f;
191         }
192
193         // Now find the effective weights that result from this sampling.
194         for (unsigned i = 0; i < num_bilinear_weights; ++i) {
195                 const float pixel_pos = to_fp64(bilinear_weights[i].pos) * size - 0.5f;
196                 const int x0 = int(floor(pixel_pos)) - lower_pos;
197                 const int x1 = x0 + 1;
198                 const float f = lrintf((pixel_pos - (x0 + lower_pos)) / movit_texel_subpixel_precision) * movit_texel_subpixel_precision;
199
200                 assert(x0 >= 0);
201                 assert(x1 >= 0);
202                 assert(x0 < upper_pos - lower_pos);
203                 assert(x1 < upper_pos - lower_pos);
204
205                 effective_weights[x0] += to_fp64(bilinear_weights[i].weight) * (1.0 - f);
206                 effective_weights[x1] += to_fp64(bilinear_weights[i].weight) * f;
207         }
208
209         // Subtract the desired weights to get the error.
210         for (unsigned i = 0; i < num_weights; ++i) {
211                 const int x = lrintf(weights[i].pos * size - 0.5f) - lower_pos;
212                 assert(x >= 0);
213                 assert(x < upper_pos - lower_pos);
214
215                 effective_weights[x] -= weights[i].weight;
216         }
217
218         double sum_sq_error = 0.0;
219         for (unsigned i = 0; i < num_weights; ++i) {
220                 sum_sq_error += effective_weights[i] * effective_weights[i];
221         }
222
223         delete[] effective_weights;
224         return sum_sq_error;
225 }
226
227 }  // namespace
228
229 ResampleEffect::ResampleEffect()
230         : input_width(1280),
231           input_height(720),
232           offset_x(0.0f), offset_y(0.0f),
233           zoom_x(1.0f), zoom_y(1.0f),
234           zoom_center_x(0.5f), zoom_center_y(0.5f)
235 {
236         register_int("width", &output_width);
237         register_int("height", &output_height);
238
239         // The first blur pass will forward resolution information to us.
240         hpass = new SingleResamplePassEffect(this);
241         CHECK(hpass->set_int("direction", SingleResamplePassEffect::HORIZONTAL));
242         vpass = new SingleResamplePassEffect(NULL);
243         CHECK(vpass->set_int("direction", SingleResamplePassEffect::VERTICAL));
244
245         update_size();
246 }
247
248 void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self)
249 {
250         Node *hpass_node = graph->add_node(hpass);
251         Node *vpass_node = graph->add_node(vpass);
252         graph->connect_nodes(hpass_node, vpass_node);
253         graph->replace_receiver(self, hpass_node);
254         graph->replace_sender(self, vpass_node);
255         self->disabled = true;
256
257
258 // We get this information forwarded from the first blur pass,
259 // since we are not part of the chain ourselves.
260 void ResampleEffect::inform_input_size(unsigned input_num, unsigned width, unsigned height)
261 {
262         assert(input_num == 0);
263         assert(width != 0);
264         assert(height != 0);
265         input_width = width;
266         input_height = height;
267         update_size();
268 }
269
270 void ResampleEffect::update_size()
271 {
272         bool ok = true;
273         ok |= hpass->set_int("input_width", input_width);
274         ok |= hpass->set_int("input_height", input_height);
275         ok |= hpass->set_int("output_width", output_width);
276         ok |= hpass->set_int("output_height", input_height);
277
278         ok |= vpass->set_int("input_width", output_width);
279         ok |= vpass->set_int("input_height", input_height);
280         ok |= vpass->set_int("output_width", output_width);
281         ok |= vpass->set_int("output_height", output_height);
282
283         assert(ok);
284
285         // The offset added due to zoom may have changed with the size.
286         update_offset_and_zoom();
287 }
288
289 void ResampleEffect::update_offset_and_zoom()
290 {
291         bool ok = true;
292
293         // Zoom from the right origin. (zoom_center is given in normalized coordinates,
294         // i.e. 0..1.)
295         float extra_offset_x = zoom_center_x * (1.0f - 1.0f / zoom_x) * input_width;
296         float extra_offset_y = (1.0f - zoom_center_y) * (1.0f - 1.0f / zoom_y) * input_height;
297
298         ok |= hpass->set_float("offset", extra_offset_x + offset_x);
299         ok |= vpass->set_float("offset", extra_offset_y - offset_y);  // Compensate for the bottom-left origin.
300         ok |= hpass->set_float("zoom", zoom_x);
301         ok |= vpass->set_float("zoom", zoom_y);
302
303         assert(ok);
304 }
305
306 bool ResampleEffect::set_float(const string &key, float value) {
307         if (key == "width") {
308                 output_width = value;
309                 update_size();
310                 return true;
311         }
312         if (key == "height") {
313                 output_height = value;
314                 update_size();
315                 return true;
316         }
317         if (key == "top") {
318                 offset_y = value;
319                 update_offset_and_zoom();
320                 return true;
321         }
322         if (key == "left") {
323                 offset_x = value;
324                 update_offset_and_zoom();
325                 return true;
326         }
327         if (key == "zoom_x") {
328                 if (value <= 0.0f) {
329                         return false;
330                 }
331                 zoom_x = value;
332                 update_offset_and_zoom();
333                 return true;
334         }
335         if (key == "zoom_y") {
336                 if (value <= 0.0f) {
337                         return false;
338                 }
339                 zoom_y = value;
340                 update_offset_and_zoom();
341                 return true;
342         }
343         if (key == "zoom_center_x") {
344                 zoom_center_x = value;
345                 update_offset_and_zoom();
346                 return true;
347         }
348         if (key == "zoom_center_y") {
349                 zoom_center_y = value;
350                 update_offset_and_zoom();
351                 return true;
352         }
353         return false;
354 }
355
356 SingleResamplePassEffect::SingleResamplePassEffect(ResampleEffect *parent)
357         : parent(parent),
358           direction(HORIZONTAL),
359           input_width(1280),
360           input_height(720),
361           offset(0.0),
362           zoom(1.0),
363           last_input_width(-1),
364           last_input_height(-1),
365           last_output_width(-1),
366           last_output_height(-1),
367           last_offset(0.0 / 0.0),  // NaN.
368           last_zoom(0.0 / 0.0)  // NaN.
369 {
370         register_int("direction", (int *)&direction);
371         register_int("input_width", &input_width);
372         register_int("input_height", &input_height);
373         register_int("output_width", &output_width);
374         register_int("output_height", &output_height);
375         register_float("offset", &offset);
376         register_float("zoom", &zoom);
377
378         glGenTextures(1, &texnum);
379 }
380
381 SingleResamplePassEffect::~SingleResamplePassEffect()
382 {
383         glDeleteTextures(1, &texnum);
384 }
385
386 string SingleResamplePassEffect::output_fragment_shader()
387 {
388         char buf[256];
389         sprintf(buf, "#define DIRECTION_VERTICAL %d\n", (direction == VERTICAL));
390         return buf + read_file("resample_effect.frag");
391 }
392
393 // Using vertical scaling as an example:
394 //
395 // Generally out[y] = w0 * in[yi] + w1 * in[yi + 1] + w2 * in[yi + 2] + ...
396 //
397 // Obviously, yi will depend on y (in a not-quite-linear way), but so will
398 // the weights w0, w1, w2, etc.. The easiest way of doing this is to encode,
399 // for each sample, the weight and the yi value, e.g. <yi, w0>, <yi + 1, w1>,
400 // and so on. For each y, we encode these along the x-axis (since that is spare),
401 // so out[0] will read from parameters <x,y> = <0,0>, <1,0>, <2,0> and so on.
402 //
403 // For horizontal scaling, we fill in the exact same texture;
404 // the shader just interprets it differently.
405 void SingleResamplePassEffect::update_texture(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
406 {
407         unsigned src_size, dst_size;
408         if (direction == SingleResamplePassEffect::HORIZONTAL) {
409                 assert(input_height == output_height);
410                 src_size = input_width;
411                 dst_size = output_width;
412         } else if (direction == SingleResamplePassEffect::VERTICAL) {
413                 assert(input_width == output_width);
414                 src_size = input_height;
415                 dst_size = output_height;
416         } else {
417                 assert(false);
418         }
419
420         // For many resamplings (e.g. 640 -> 1280), we will end up with the same
421         // set of samples over and over again in a loop. Thus, we can compute only
422         // the first such loop, and then ask the card to repeat the texture for us.
423         // This is both easier on the texture cache and lowers our CPU cost for
424         // generating the kernel somewhat.
425         float scaling_factor;
426         if (fabs(zoom - 1.0f) < 1e-6) {
427                 num_loops = gcd(src_size, dst_size);
428                 scaling_factor = float(dst_size) / float(src_size);
429         } else {
430                 // If zooming is enabled (ie., zoom != 1), we turn off the looping.
431                 // We _could_ perhaps do it for rational zoom levels (especially
432                 // things like 2:1), but it doesn't seem to be worth it, given that
433                 // the most common use case would seem to be varying the zoom
434                 // from frame to frame.
435                 num_loops = 1;
436                 scaling_factor = zoom * float(dst_size) / float(src_size);
437         }
438         slice_height = 1.0f / num_loops;
439         unsigned dst_samples = dst_size / num_loops;
440
441         // Sample the kernel in the right place. A diagram with a triangular kernel
442         // (corresponding to linear filtering, and obviously with radius 1)
443         // for easier ASCII art drawing:
444         //
445         //                *
446         //               / \                      |
447         //              /   \                     |
448         //             /     \                    |
449         //    x---x---x   x   x---x---x---x
450         //
451         // Scaling up (in this case, 2x) means sampling more densely:
452         //
453         //                *
454         //               / \                      |
455         //              /   \                     |
456         //             /     \                    |
457         //   x-x-x-x-x-x x x x-x-x-x-x-x-x-x
458         //
459         // When scaling up, any destination pixel will only be influenced by a few
460         // (in this case, two) neighboring pixels, and more importantly, the number
461         // will not be influenced by the scaling factor. (Note, however, that the
462         // pixel centers have moved, due to OpenGL's center-pixel convention.)
463         // The only thing that changes is the weights themselves, as the sampling
464         // points are at different distances from the original pixels.
465         //
466         // Scaling down is a different story:
467         //
468         //                *
469         //               / \                      |
470         //              /   \                     |
471         //             /     \                    |
472         //    --x------ x     --x-------x--
473         //
474         // Again, the pixel centers have moved in a maybe unintuitive fashion,
475         // although when you consider that there are multiple source pixels around,
476         // it's not so bad as at first look:
477         //
478         //            *   *   *   *
479         //           / \ / \ / \ / \              |
480         //          /   X   X   X   \             |
481         //         /   / \ / \ / \   \            |
482         //    --x-------x-------x-------x--
483         //
484         // As you can see, the new pixels become averages of the two neighboring old
485         // ones (the situation for Lanczos is of course more complex).
486         //
487         // Anyhow, in this case we clearly need to look at more source pixels
488         // to compute the destination pixel, and how many depend on the scaling factor.
489         // Thus, the kernel width will vary with how much we scale.
490         float radius_scaling_factor = min(scaling_factor, 1.0f);
491         int int_radius = lrintf(LANCZOS_RADIUS / radius_scaling_factor);
492         int src_samples = int_radius * 2 + 1;
493         Tap<float> *weights = new Tap<float>[dst_samples * src_samples];
494         float subpixel_offset = offset - lrintf(offset);  // The part not covered by whole_pixel_offset.
495         assert(subpixel_offset >= -0.5f && subpixel_offset <= 0.5f);
496         for (unsigned y = 0; y < dst_samples; ++y) {
497                 // Find the point around which we want to sample the source image,
498                 // compensating for differing pixel centers as the scale changes.
499                 float center_src_y = (y + 0.5f) / scaling_factor - 0.5f;
500                 int base_src_y = lrintf(center_src_y);
501
502                 // Now sample <int_radius> pixels on each side around that point.
503                 for (int i = 0; i < src_samples; ++i) {
504                         int src_y = base_src_y + i - int_radius;
505                         float weight = lanczos_weight(radius_scaling_factor * (src_y - center_src_y - subpixel_offset), LANCZOS_RADIUS);
506                         weights[y * src_samples + i].weight = weight * radius_scaling_factor;
507                         weights[y * src_samples + i].pos = (src_y + 0.5) / float(src_size);
508                 }
509         }
510
511         // Now make use of the bilinear filtering in the GPU to reduce the number of samples
512         // we need to make. Try fp16 first; if it's not accurate enough, we go to fp32.
513         // Our tolerance level for total error is a bit higher than the one for invididual
514         // samples, since one would assume overall errors in the shape don't matter as much.
515         const float max_error = 2.0f / (255.0f * 255.0f);
516         Tap<fp16_int_t> *bilinear_weights_fp16;
517         src_bilinear_samples = combine_many_samples(weights, src_size, src_samples, dst_samples, &bilinear_weights_fp16);
518         Tap<float> *bilinear_weights_fp32 = NULL;
519         bool fallback_to_fp32 = false;
520         double max_sum_sq_error_fp16 = 0.0;
521         for (unsigned y = 0; y < dst_samples; ++y) {
522                 double sum_sq_error_fp16 = compute_sum_sq_error(
523                         weights + y * src_samples, src_samples,
524                         bilinear_weights_fp16 + y * src_bilinear_samples, src_bilinear_samples,
525                         src_size);
526                 max_sum_sq_error_fp16 = std::max(max_sum_sq_error_fp16, sum_sq_error_fp16);
527                 if (max_sum_sq_error_fp16 > max_error) {
528                         break;
529                 }
530         }
531
532         if (max_sum_sq_error_fp16 > max_error) {
533                 fallback_to_fp32 = true;
534                 src_bilinear_samples = combine_many_samples(weights, src_size, src_samples, dst_samples, &bilinear_weights_fp32);
535         }
536
537         // Encode as a two-component texture. Note the GL_REPEAT.
538         glActiveTexture(GL_TEXTURE0 + *sampler_num);
539         check_error();
540         glBindTexture(GL_TEXTURE_2D, texnum);
541         check_error();
542         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
543         check_error();
544         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
545         check_error();
546         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
547         check_error();
548         if (fallback_to_fp32) {
549                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, src_bilinear_samples, dst_samples, 0, GL_RG, GL_FLOAT, bilinear_weights_fp32);
550         } else {
551                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, src_bilinear_samples, dst_samples, 0, GL_RG, GL_HALF_FLOAT, bilinear_weights_fp16);
552         }
553         check_error();
554
555         delete[] weights;
556         delete[] bilinear_weights_fp16;
557         delete[] bilinear_weights_fp32;
558 }
559
560 void SingleResamplePassEffect::set_gl_state(GLuint glsl_program_num, const string &prefix, unsigned *sampler_num)
561 {
562         Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
563
564         assert(input_width > 0);
565         assert(input_height > 0);
566         assert(output_width > 0);
567         assert(output_height > 0);
568
569         if (input_width != last_input_width ||
570             input_height != last_input_height ||
571             output_width != last_output_width ||
572             output_height != last_output_height ||
573             offset != last_offset ||
574             zoom != last_zoom) {
575                 update_texture(glsl_program_num, prefix, sampler_num);
576                 last_input_width = input_width;
577                 last_input_height = input_height;
578                 last_output_width = output_width;
579                 last_output_height = output_height;
580                 last_offset = offset;
581                 last_zoom = zoom;
582         }
583
584         glActiveTexture(GL_TEXTURE0 + *sampler_num);
585         check_error();
586         glBindTexture(GL_TEXTURE_2D, texnum);
587         check_error();
588
589         set_uniform_int(glsl_program_num, prefix, "sample_tex", *sampler_num);
590         ++*sampler_num;
591         set_uniform_int(glsl_program_num, prefix, "num_samples", src_bilinear_samples);
592         set_uniform_float(glsl_program_num, prefix, "num_loops", num_loops);
593         set_uniform_float(glsl_program_num, prefix, "slice_height", slice_height);
594
595         // Instructions for how to convert integer sample numbers to positions in the weight texture.
596         set_uniform_float(glsl_program_num, prefix, "sample_x_scale", 1.0f / src_bilinear_samples);
597         set_uniform_float(glsl_program_num, prefix, "sample_x_offset", 0.5f / src_bilinear_samples);
598
599         float whole_pixel_offset;
600         if (direction == SingleResamplePassEffect::VERTICAL) {
601                 whole_pixel_offset = lrintf(offset) / float(input_height);
602         } else {
603                 whole_pixel_offset = lrintf(offset) / float(input_width);
604         }
605         set_uniform_float(glsl_program_num, prefix, "whole_pixel_offset", whole_pixel_offset);
606
607         // We specifically do not want mipmaps on the input texture;
608         // they break minification.
609         Node *self = chain->find_node_for_effect(this);
610         glActiveTexture(chain->get_input_sampler(self, 0));
611         check_error();
612         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
613         check_error();
614 }
615
616 }  // namespace movit