X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=util.cpp;h=b12ee80712ba83e541f28472760167e5e8fb1d22;hp=7fbc67a07206b81df5a196c580e704a1ba369444;hb=185ced44b129739c9b5438da691e71d664d6443a;hpb=fe7a508885d19950c43e46dc60db675375f49ffb diff --git a/util.cpp b/util.cpp index 7fbc67a..b12ee80 100644 --- a/util.cpp +++ b/util.cpp @@ -158,8 +158,9 @@ string output_glsl_mat3(const string &name, const Eigen::Matrix3d &m) return buf; } -void combine_two_samples(float w1, float w2, float pos1, float pos2, unsigned size, CombineRoundingBehavior rounding_behavior, - float *offset, float *total_weight, float *sum_sq_error) +template +void combine_two_samples(float w1, float w2, float pos1, float pos2, unsigned size, + DestFloat *offset, DestFloat *total_weight, float *sum_sq_error) { assert(movit_initialized); assert(w1 * w2 >= 0.0f); // Should not have differing signs. @@ -170,14 +171,9 @@ void combine_two_samples(float w1, float w2, float pos1, float pos2, unsigned si z = w2 / (w1 + w2); } - *offset = pos1 + z * (pos2 - pos1); - if (rounding_behavior == COMBINE_ROUND_TO_FP16) { - // Round to fp16. Note that this might take z outside the 0..1 range. - *offset = fp16_to_fp64(fp64_to_fp16(*offset)); - z = (*offset - pos1) / (pos2 - pos1); - } else { - assert(rounding_behavior == COMBINE_DO_NOT_ROUND); - } + // Round to the desired precision. Note that this might take z outside the 0..1 range. + *offset = from_fp64(pos1 + z * (pos2 - pos1)); + z = (to_fp64(*offset) - pos1) / (pos2 - pos1); // 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 @@ -208,6 +204,15 @@ void combine_two_samples(float w1, float w2, float pos1, float pos2, unsigned si } } +// Explicit instantiations. +template +void combine_two_samples(float w1, float w2, float pos1, float pos2, unsigned size, + float *offset, float *total_weight, float *sum_sq_error); + +template +void combine_two_samples(float w1, float w2, float pos1, float pos2, unsigned size, + fp16_int_t *offset, fp16_int_t *total_weight, float *sum_sq_error); + GLuint fill_vertex_attribute(GLuint glsl_program_num, const string &attribute_name, GLint size, GLenum type, GLsizeiptr data_size, const GLvoid *data) { int attrib = glGetAttribLocation(glsl_program_num, attribute_name.c_str());