float w2 = weight[base_pos + 1];
float pos1 = base_pos / (float)size;
- float pos2 = (base_pos + 1) / (float)size;
float pos, total_weight;
- combine_two_samples(w1, w2, pos1, pos2, num_subtexels, inv_num_subtexels, &pos, &total_weight, NULL);
+ combine_two_samples(w1, w2, pos1, 1.0 / (float)size, size, num_subtexels, inv_num_subtexels, &pos, &total_weight, NULL);
uniform_samples[2 * i + 0] = pos;
uniform_samples[2 * i + 1] = total_weight;
}
template<class DestFloat>
-unsigned combine_samples(const Tap<float> *src, Tap<DestFloat> *dst, float num_subtexels, float inv_num_subtexels, unsigned num_src_samples, unsigned max_samples_saved)
+unsigned combine_samples(const Tap<float> *src, Tap<DestFloat> *dst, float num_subtexels, float inv_num_subtexels, unsigned num_src_samples, unsigned max_samples_saved, float pos1_pos2_diff, float inv_pos1_pos2_diff)
{
// Cut off near-zero values at both sides.
unsigned num_samples_saved = 0;
DestFloat pos, total_weight;
float sum_sq_error;
- combine_two_samples(w1, w2, pos1, pos2, num_subtexels, inv_num_subtexels, &pos, &total_weight, &sum_sq_error);
+ combine_two_samples(w1, w2, pos1, pos1_pos2_diff, inv_pos1_pos2_diff, num_subtexels, inv_num_subtexels, &pos, &total_weight, &sum_sq_error);
// If the interpolation error is larger than that of about sqrt(2) of
// a level at 8-bit precision, don't combine. (You'd think 1.0 was enough,
{
float num_subtexels = src_size / movit_texel_subpixel_precision;
float inv_num_subtexels = movit_texel_subpixel_precision / src_size;
+ float pos1_pos2_diff = 1.0f / src_size;
+ float inv_pos1_pos2_diff = src_size;
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);
+ unsigned num_samples_saved = combine_samples<DestFloat>(weights + y * src_samples, NULL, num_subtexels, inv_num_subtexels, src_samples, max_samples_saved, pos1_pos2_diff, inv_pos1_pos2_diff);
max_samples_saved = min(max_samples_saved, num_samples_saved);
}
num_subtexels,
inv_num_subtexels,
src_samples,
- max_samples_saved);
+ max_samples_saved,
+ pos1_pos2_diff,
+ inv_pos1_pos2_diff);
assert(num_samples_saved == max_samples_saved);
normalize_sum(bilinear_weights_ptr, src_bilinear_samples);
}
}
template<class DestFloat>
-void combine_two_samples(float w1, float w2, float pos1, float pos2, float num_subtexels, float inv_num_subtexels,
+void combine_two_samples(float w1, float w2, float pos1, float pos1_pos2_diff, float inv_pos1_pos2_diff, float num_subtexels, float inv_num_subtexels,
DestFloat *offset, DestFloat *total_weight, float *sum_sq_error)
{
assert(movit_initialized);
}
// Round to the desired precision. Note that this might take z outside the 0..1 range.
- *offset = from_fp32<DestFloat>(pos1 + z * (pos2 - pos1));
- z = (to_fp32(*offset) - pos1) / (pos2 - pos1);
+ *offset = from_fp32<DestFloat>(pos1 + z * pos1_pos2_diff);
+ z = (to_fp32(*offset) - pos1) * inv_pos1_pos2_diff;
// Round to the minimum number of bits we have measured earlier.
// The card will do this for us anyway, but if we know what the real z
// Explicit instantiations.
template
-void combine_two_samples<float>(float w1, float w2, float pos1, float pos2, float num_subtexels, float inv_num_subtexels,
+void combine_two_samples<float>(float w1, float w2, float pos1, float pos1_pos2_diff, float inv_pos1_pos2_diff, float num_subtexels, float inv_num_subtexels,
float *offset, float *total_weight, float *sum_sq_error);
template
-void combine_two_samples<fp16_int_t>(float w1, float w2, float pos1, float pos2, float num_subtexels, float inv_num_subtexels,
+void combine_two_samples<fp16_int_t>(float w1, float w2, float pos1, float pos1_pos2_diff, float inv_pos1_pos2_diff, float num_subtexels, float inv_num_subtexels,
fp16_int_t *offset, fp16_int_t *total_weight, float *sum_sq_error);
GLuint generate_vbo(GLint size, GLenum type, GLsizeiptr data_size, const GLvoid *data)
// number of distinct accessible subtexels in the given mipmap level,
// calculated by num_texels / movit_texel_subpixel_precision. It is a float
// for performance reasons, even though it is expected to be a whole number.
-// <inv_num_subtexels> is simply its inverse (1/x).
+// <inv_num_subtexels> is simply its inverse (1/x). <pos1_pos2_diff> is
+// (pos2-pos1) and <inv_pos1_pos2_diff> is 1/(pos2-pos1).
//
// Note that since the GPU might have limited precision in its linear
// interpolation, the effective weights might be different from the ones you
// rounded fp16 value. This enables more precise calculation of total_weight
// and sum_sq_error.
template<class DestFloat>
-void combine_two_samples(float w1, float w2, float pos1, float pos2, float num_subtexels, float inv_num_subtexels,
+void combine_two_samples(float w1, float w2, float pos1, float pos1_pos2_diff, float inv_pos1_pos2_diff, float num_subtexels, float inv_num_subtexels,
DestFloat *offset, DestFloat *total_weight, float *sum_sq_error);
// Create a VBO with the given data. Returns the VBO number.