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)
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) {
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);
}
""",
r'expression int16_t bitfield_insert \(expression int16_t'),
+ Test("bitCount",
+ """
+ #version 310 es
+ precision mediump float;
+ precision mediump int;
+
+ uniform highp int val;
+ out int color;
+
+ void main()
+ {
+ color = bitCount(val) + 1;
+ }
+ """,
+ r'expression int16_t \+ \(expression int16_t i2imp \(expression int bit_count \(var_ref val'),
+ Test("findLSB",
+ """
+ #version 310 es
+ precision mediump float;
+ precision mediump int;
+
+ uniform highp int val;
+ out int color;
+
+ void main()
+ {
+ color = findLSB(val) + 1;
+ }
+ """,
+ r'expression int16_t \+ \(expression int16_t i2imp \(expression int find_lsb \(var_ref val'),
+ Test("findMSB",
+ """
+ #version 310 es
+ precision mediump float;
+ precision mediump int;
+
+ uniform highp int val;
+ out int color;
+
+ void main()
+ {
+ color = findMSB(val) + 1;
+ }
+ """,
+ r'expression int16_t \+ \(expression int16_t i2imp \(expression int find_msb \(var_ref val'),
+ Test("unpackHalf2x16",
+ """
+ #version 310 es
+ precision mediump float;
+ precision mediump int;
+
+ uniform highp uint val;
+ out vec2 color;
+
+ void main()
+ {
+ color = unpackHalf2x16(val) + vec2(1.0);
+ }
+ """,
+ r'expression f16vec2 \+ \(expression f16vec2 f2fmp \(expression vec2 unpackHalf2x16 \(var_ref val'),
+ Test("unpackUnorm4x8",
+ """
+ #version 310 es
+ precision mediump float;
+ precision mediump int;
+
+ uniform highp uint val;
+ out vec4 color;
+
+ void main()
+ {
+ color = unpackUnorm4x8(val) + vec4(1.0);
+ }
+ """,
+ r'expression f16vec4 \+ \(expression f16vec4 f2fmp \(expression vec4 unpackUnorm4x8 \(var_ref val'),
+ Test("unpackSnorm4x8",
+ """
+ #version 310 es
+ precision mediump float;
+ precision mediump int;
+
+ uniform highp uint val;
+ out vec4 color;
+
+ void main()
+ {
+ color = unpackSnorm4x8(val) + vec4(1.0);
+ }
+ """,
+ r'expression f16vec4 \+ \(expression f16vec4 f2fmp \(expression vec4 unpackSnorm4x8 \(var_ref val'),
]