panfrost/midgard: Safety check immediate precision degradations
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 28 Apr 2019 15:46:47 +0000 (15:46 +0000)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 28 Apr 2019 21:34:32 +0000 (21:34 +0000)
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/gallium/drivers/panfrost/midgard/midgard_compile.c

index 2b97bbc86f636cd8bc4458bb61ff71456cd80280..348ec861404a281943efd8be0d401599f08aa366 100644 (file)
@@ -3047,7 +3047,20 @@ embedded_to_inline_constant(compiler_context *ctx)
                                 if (scaled_constant != iconstants[component])
                                         continue;
                         } else {
-                                scaled_constant = _mesa_float_to_half((float) ins->constants[component]);
+                                float original = (float) ins->constants[component];
+                                scaled_constant = _mesa_float_to_half(original);
+
+                                /* Check for loss of precision. If this is
+                                 * mediump, we don't care, but for a highp
+                                 * shader, we need to pay attention. NIR
+                                 * doesn't yet tell us which mode we're in!
+                                 * Practically this prevents most constants
+                                 * from being inlined, sadly. */
+
+                                float fp32 = _mesa_half_to_float(scaled_constant);
+
+                                if (fp32 != original)
+                                        continue;
                         }
 
                         /* We don't know how to handle these with a constant */