This works by finding the first rvalue that it can lower using an ir_rvalue_visitor. In that case it adds a conversion to float16 after each rvalue and a conversion back to float before storing the assignment.
Also it uses a set to keep track of rvalues that have been lowred already. The handle_rvalue method of the rvalue visitor doesn’t provide any way to stop iteration. If we handle a value in find_precision_visitor we want to be able to stop it from descending into the lowered rvalue again.
Additionally this pass disallows converting nodes containing non-float. The can_lower_rvalue function explicitly excludes any branches that have non-float types except bools. This avoids the need to have special handling for functions that convert to int or double.
b83f4b9fa23 glsl: Add an IR lowering pass to convert mediump operations to 16-bit
src/compiler/Makefile.sources | 1 +
src/compiler/glsl/glsl_parser_extras.cpp | 5 +
src/compiler/glsl/glsl_to_nir.cpp | 3 +
src/compiler/glsl/ir_optimization.h | 2 +
src/compiler/glsl/lower_precision.cpp | 618 +++++++++++++++++++++++++++++++
src/compiler/glsl/meson.build | 1 +
src/mesa/main/mtypes.h | 6 +
src/mesa/state_tracker/st_extensions.c | 6 +
8 files changed, 642 insertions(+)