return visit_continue;
}
+static bool
+function_always_returns_mediump_or_lowp(const char *name)
+{
+ return !strcmp(name, "bitCount") ||
+ !strcmp(name, "findLSB") ||
+ !strcmp(name, "findMSB") ||
+ !strcmp(name, "unpackHalf2x16") ||
+ !strcmp(name, "unpackUnorm4x8") ||
+ !strcmp(name, "unpackSnorm4x8");
+}
+
static bool
is_lowerable_builtin(ir_call *ir,
const struct set *lowerable_rvalues)
assert(ir->callee->return_precision == GLSL_PRECISION_NONE);
+ /* Number of parameters to check if they are lowerable. */
+ unsigned check_parameters = ir->actual_parameters.length();
+
+ /* Interpolation functions only consider the precision of the interpolant. */
+ /* Bitfield functions ignore the precision of "offset" and "bits". */
+ if (!strcmp(ir->callee_name(), "interpolateAtOffset") ||
+ !strcmp(ir->callee_name(), "interpolateAtSample") ||
+ !strcmp(ir->callee_name(), "bitfieldExtract")) {
+ check_parameters = 1;
+ } else if (!strcmp(ir->callee_name(), "bitfieldInsert")) {
+ check_parameters = 2;
+ } if (function_always_returns_mediump_or_lowp(ir->callee_name())) {
+ /* These only lower the return value. Parameters keep their precision,
+ * which is preserved in map_builtin.
+ */
+ check_parameters = 0;
+ }
+
foreach_in_list(ir_rvalue, param, &ir->actual_parameters) {
+ if (!check_parameters)
+ break;
+
if (!param->as_constant() &&
_mesa_set_search(lowerable_rvalues, param) == NULL)
return false;
+
+ --check_parameters;
}
return true;
ir_function_signature *lowered_sig =
sig->clone(lowered_builtin_mem_ctx, clone_ht);
- foreach_in_list(ir_variable, param, &lowered_sig->parameters) {
- param->data.precision = GLSL_PRECISION_MEDIUM;
+ /* Functions that always return mediump or lowp should keep their
+ * parameters intact, because they can be highp. NIR can lower
+ * the up-conversion for parameters if needed.
+ */
+ if (!function_always_returns_mediump_or_lowp(sig->function_name())) {
+ foreach_in_list(ir_variable, param, &lowered_sig->parameters) {
+ param->data.precision = GLSL_PRECISION_MEDIUM;
+ }
}
lower_precision(options, &lowered_sig->body);