glsl: lower mediump partial derivatives
authorMarek Olšák <marek.olsak@amd.com>
Sun, 10 May 2020 01:38:34 +0000 (21:38 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 2 Jun 2020 20:01:18 +0000 (20:01 +0000)
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5002>

src/compiler/glsl/lower_precision.cpp
src/compiler/glsl/standalone.cpp
src/compiler/glsl/tests/lower_precision_test.py
src/mesa/main/mtypes.h

index 44cc7969204d784a9d38c1d5fd7f13d5e753657c..b410e3290a2466daacf7aff9972cb271dbde8442 100644 (file)
@@ -399,12 +399,13 @@ find_lowerable_rvalues_visitor::visit_enter(ir_expression *ir)
       stack.back().state = CANT_LOWER;
 
    /* Don't lower precision for derivative calculations */
-   if (ir->operation == ir_unop_dFdx ||
-         ir->operation == ir_unop_dFdx_coarse ||
-         ir->operation == ir_unop_dFdx_fine ||
-         ir->operation == ir_unop_dFdy ||
-         ir->operation == ir_unop_dFdy_coarse ||
-         ir->operation == ir_unop_dFdy_fine) {
+   if (!options->LowerPrecisionDerivatives &&
+       (ir->operation == ir_unop_dFdx ||
+        ir->operation == ir_unop_dFdx_coarse ||
+        ir->operation == ir_unop_dFdx_fine ||
+        ir->operation == ir_unop_dFdy ||
+        ir->operation == ir_unop_dFdy_coarse ||
+        ir->operation == ir_unop_dFdy_fine)) {
       stack.back().state = CANT_LOWER;
    }
 
index 02f019e0bde280f983b802bc883fba020a4a6f1e..5b34297df59650272c94f1574392d779e2a35046 100644 (file)
@@ -440,6 +440,7 @@ standalone_compile_shader(const struct standalone_options *_options,
             &ctx->Const.ShaderCompilerOptions[i];
          options->LowerPrecisionFloat16 = true;
          options->LowerPrecisionInt16 = true;
+         options->LowerPrecisionDerivatives = true;
       }
    }
 
index 0934e61e4ab7d3b88234c128c5fdd12e015cacec..3626d8d2a4b71dd8b62bc8c9e8af4e41eda3b6b3 100644 (file)
@@ -1035,6 +1035,34 @@ TESTS = [
          }
          """,
          r'\(expression +uint16_t min'),
+    Test("dFdx",
+         """
+         #version 300 es
+         precision mediump float;
+
+         in vec4 var;
+         out vec4 color;
+
+         void main()
+         {
+                 color = dFdx(var);
+         }
+         """,
+         r'\(expression +f16vec4 +dFdx +\(expression +f16vec4'),
+    Test("dFdy",
+         """
+         #version 300 es
+         precision mediump float;
+
+         in vec4 var;
+         out vec4 color;
+
+         void main()
+         {
+                 color = dFdy(var);
+         }
+         """,
+         r'\(expression +f16vec4 +dFdy +\(expression +f16vec4'),
 ]
 
 
index 5eb4ba625d45f13aaf65ee81d1687bff81984b24..eff6f496eb663cd53a5d596214878ccedd41940c 100644 (file)
@@ -3208,6 +3208,7 @@ struct gl_shader_compiler_options
     */
    GLboolean LowerPrecisionFloat16;
    GLboolean LowerPrecisionInt16;
+   GLboolean LowerPrecisionDerivatives;
 
    /**
     * \name Forms of indirect addressing the driver cannot do.