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<class DestFloat>
+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.
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 = (z - 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<DestFloat>(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
}
}
+// Explicit instantiations.
+template
+void combine_two_samples<float>(float w1, float w2, float pos1, float pos2, unsigned size,
+ 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, 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());