glsl/lower_precision: split out const lowering
authorRob Clark <robdclark@chromium.org>
Wed, 5 Aug 2020 16:56:52 +0000 (09:56 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 5 Aug 2020 21:00:44 +0000 (21:00 +0000)
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 <robdclark@chromium.org>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6189>

src/compiler/glsl/lower_precision.cpp
src/compiler/glsl/standalone.cpp
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_extensions.c

index 1f116cd40ff9c09712a45554155d31ea2f37d7ac..07798f3b200d18143634f34147a2cbbdfbe66253 100644 (file)
@@ -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);
index f0305f735bbb4f73d3d08ca883c5dc81b1a81886..c1510d51e0b830c864b2e9f707000daa8bcef2fd 100644 (file)
@@ -442,6 +442,7 @@ standalone_compile_shader(const struct standalone_options *_options,
          options->LowerPrecisionInt16 = true;
          options->LowerPrecisionDerivatives = true;
          options->LowerPrecisionTemporaries = true;
+         options->LowerPrecisionConstants = true;
       }
    }
 
index a6af3fbca17eac7ab5cde26d81441ba662d6d549..1df6d34b5d4aef22f77a76a9c27926efae08bf5e 100644 (file)
@@ -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.
index e39ee75905e66473df1f2b2f4eb57e8e8c83e0c3..331df122ddaf55a3b48cdf11e8926629813f9319 100644 (file)
@@ -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 =