From: Rob Clark Date: Wed, 5 Aug 2020 16:56:52 +0000 (-0700) Subject: glsl/lower_precision: split out const lowering X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0a763c0c86bb9845c2eac9726690d83b82d46978;p=mesa.git glsl/lower_precision: split out const lowering Some hw can narrow 32b const/uniform to 16b on load.. and in particular lowering constants to 16b would break const->uniform lowering. Allow them to lower temps to 16b, while skipping consts. Initially it is set to the same value as LowerPrecisionTemporaries, to preserve the current behavior. Signed-off-by: Rob Clark Reviewed-by: Alyssa Rosenzweig Reviewed-by: Marek Olšák Reviewed-by: Eric Anholt Part-of: --- diff --git a/src/compiler/glsl/lower_precision.cpp b/src/compiler/glsl/lower_precision.cpp index 1f116cd40ff..07798f3b200 100644 --- a/src/compiler/glsl/lower_precision.cpp +++ b/src/compiler/glsl/lower_precision.cpp @@ -1028,6 +1028,8 @@ lower_variables_visitor::visit(ir_variable *var) /* Lower constant initializers. */ if (var->constant_value && var->type == var->constant_value->type) { + if (!options->LowerPrecisionConstants) + return visit_continue; var->constant_value = var->constant_value->clone(ralloc_parent(var), NULL); lower_constant(var->constant_value); @@ -1035,6 +1037,8 @@ lower_variables_visitor::visit(ir_variable *var) if (var->constant_initializer && var->type == var->constant_initializer->type) { + if (!options->LowerPrecisionConstants) + return visit_continue; var->constant_initializer = var->constant_initializer->clone(ralloc_parent(var), NULL); lower_constant(var->constant_initializer); diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp index f0305f735bb..c1510d51e0b 100644 --- a/src/compiler/glsl/standalone.cpp +++ b/src/compiler/glsl/standalone.cpp @@ -442,6 +442,7 @@ standalone_compile_shader(const struct standalone_options *_options, options->LowerPrecisionInt16 = true; options->LowerPrecisionDerivatives = true; options->LowerPrecisionTemporaries = true; + options->LowerPrecisionConstants = true; } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index a6af3fbca17..1df6d34b5d4 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3210,6 +3210,13 @@ struct gl_shader_compiler_options GLboolean LowerPrecisionInt16; GLboolean LowerPrecisionDerivatives; + /** + * This enables lowering of 16b constants. Some drivers may not + * to lower constants to 16b (ie. if the hw can do automatic + * narrowing on constant load) + */ + GLboolean LowerPrecisionConstants; + /** * This enables 16-bit phis in NIR, 16-bit loop counters, 16-bit indirect * arrays, etc. diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index e39ee75905e..331df122dda 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -348,6 +348,7 @@ void st_init_limits(struct pipe_screen *screen, screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_INT16); options->LowerPrecisionTemporaries = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_GLSL_16BIT_TEMPS); + options->LowerPrecisionConstants = options->LowerPrecisionTemporaries; } c->MaxUserAssignableUniformLocations =