In ResampleEffect, be more aggressive about giving up on saving bilinear samples.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Sep 2015 18:05:43 +0000 (20:05 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Sep 2015 18:05:43 +0000 (20:05 +0200)
It turns out that for some kinds of loads, we can't use bilinearity at all
to our benefit, so we spend almost all of our time trying to go through
each line to see how much we can save. Simply send in the minimum number
so far when doing this evaluation to begin with, which means we'll effectively
short-circuit the entire thing pretty fast once we find a line that can save
nothing.

resample_effect.cpp

index 79d5f21..1b74a96 100644 (file)
@@ -161,14 +161,15 @@ unsigned combine_many_samples(const Tap<float> *weights, unsigned src_size, unsi
 {
        float num_subtexels = src_size / movit_texel_subpixel_precision;
        float inv_num_subtexels = movit_texel_subpixel_precision / src_size;
-       int src_bilinear_samples = 0;
 
-       for (unsigned y = 0; y < dst_samples; ++y) {
-               unsigned num_samples_saved = combine_samples<DestFloat>(weights + y * src_samples, NULL, num_subtexels, inv_num_subtexels, src_samples, UINT_MAX);
-               src_bilinear_samples = max<int>(src_bilinear_samples, src_samples - num_samples_saved);
+       unsigned max_samples_saved = UINT_MAX;
+       for (unsigned y = 0; y < dst_samples && max_samples_saved > 0; ++y) {
+               unsigned num_samples_saved = combine_samples<DestFloat>(weights + y * src_samples, NULL, num_subtexels, inv_num_subtexels, src_samples, max_samples_saved);
+               max_samples_saved = min(max_samples_saved, num_samples_saved);
        }
 
        // Now that we know the right width, actually combine the samples.
+       unsigned src_bilinear_samples = src_samples - max_samples_saved;
        *bilinear_weights = new Tap<DestFloat>[dst_samples * src_bilinear_samples];
        for (unsigned y = 0; y < dst_samples; ++y) {
                Tap<DestFloat> *bilinear_weights_ptr = *bilinear_weights + y * src_bilinear_samples;
@@ -178,8 +179,8 @@ unsigned combine_many_samples(const Tap<float> *weights, unsigned src_size, unsi
                        num_subtexels,
                        inv_num_subtexels,
                        src_samples,
-                       src_samples - src_bilinear_samples);
-               assert(int(src_samples) - int(num_samples_saved) == src_bilinear_samples);
+                       max_samples_saved);
+               assert(num_samples_saved == max_samples_saved);
                normalize_sum(bilinear_weights_ptr, src_bilinear_samples);
        }
        return src_bilinear_samples;