glsl: lower mediump uniforms to FP16 based on an option

Everything else is done - just allow it.

v2: update lower_precision_test.py

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> (v1)
Reviewed-by: Eric Anholt <eric@anholt.net> (v1)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9050>
This commit is contained in:
Marek Olšák 2021-02-12 09:44:04 -05:00 committed by Marge Bot
parent 43270e24b9
commit b19a836413
4 changed files with 10 additions and 3 deletions

View file

@ -1023,7 +1023,12 @@ ir_visitor_status
lower_variables_visitor::visit(ir_variable *var)
{
if ((var->data.mode != ir_var_temporary &&
var->data.mode != ir_var_auto) ||
var->data.mode != ir_var_auto &&
/* Lower uniforms but not UBOs. */
(var->data.mode != ir_var_uniform ||
var->is_in_buffer_block() ||
!(options->LowerPrecisionFloat16Uniforms &&
var->type->without_array()->base_type == GLSL_TYPE_FLOAT))) ||
!var->type->without_array()->is_32bit() ||
(var->data.precision != GLSL_PRECISION_MEDIUM &&
var->data.precision != GLSL_PRECISION_LOW) ||

View file

@ -439,6 +439,7 @@ standalone_compile_shader(const struct standalone_options *_options,
options->LowerPrecisionInt16 = true;
options->LowerPrecisionDerivatives = true;
options->LowerPrecisionConstants = true;
options->LowerPrecisionFloat16Uniforms = true;
}
}

View file

@ -689,7 +689,7 @@ TESTS = [
gl_FragColor = vec4(b * a, 0.0, 0.0);
}
""",
r'\(expression +f16vec2 \*.*\bf16mat2\b'),
r'\(expression +f16vec2 \* \(var_ref b\) \(var_ref a\)'),
Test("f32 simple struct deref",
"""
precision mediump float;
@ -1685,7 +1685,7 @@ TESTS = [
color += x;
}
""",
r'\(assign \(x\) \(var_ref x\) \(expression float16_t \+ \(var_ref x\) \(expression float16_t f2fmp \(var_ref incr'),
r'\(assign \(x\) \(var_ref x\) \(expression float16_t \+ \(var_ref x\) \(var_ref incr'),
Test("i32 loop counter",
"""
#version 310 es

View file

@ -3253,6 +3253,7 @@ struct gl_shader_compiler_options
GLboolean LowerPrecisionFloat16;
GLboolean LowerPrecisionInt16;
GLboolean LowerPrecisionDerivatives;
GLboolean LowerPrecisionFloat16Uniforms;
/**
* This enables lowering of 16b constants. Some drivers may not