Enable narrowing conversions automatically for Runtime Effects.

Previously, it was possible to compile runtime effects with narrowing
conversions disabled; e.g. skslc would do this. A Runtime Effect-based
ProgramKind now enables narrowing conversions automatically. (The
setting flag could still be turned on manually as well.)

Change-Id: I912c9adda77c29ccfda3b1d85d106315f648d624
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/435916
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/core/SkRuntimeEffect.cpp b/src/core/SkRuntimeEffect.cpp
index 023a91e..256b4d9 100644
--- a/src/core/SkRuntimeEffect.cpp
+++ b/src/core/SkRuntimeEffect.cpp
@@ -226,7 +226,6 @@
         settings.fInlineThreshold = 0;
         settings.fForceNoInline = options.forceNoInline;
         settings.fEnforceES2Restrictions = options.enforceES2Restrictions;
-        settings.fAllowNarrowingConversions = true;
         program = compiler->convertProgram(kind, SkSL::String(sksl.c_str(), sksl.size()), settings);
 
         if (!program) {
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 275eb94..d78b0cd 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -459,6 +459,11 @@
     settings.fRemoveDeadFunctions &= settings.fOptimize;
     settings.fRemoveDeadVariables &= settings.fOptimize;
 
+    // Runtime effects always allow narrowing conversions.
+    if (ProgramConfig::IsRuntimeEffect(kind)) {
+        settings.fAllowNarrowingConversions = true;
+    }
+
     fErrorText = "";
     fErrorCount = 0;
     fInliner.reset();
diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h
index 502fdc8..26df2d9 100644
--- a/src/sksl/SkSLIRGenerator.h
+++ b/src/sksl/SkSLIRGenerator.h
@@ -245,7 +245,7 @@
     }
 
     bool isRuntimeEffect() const {
-        return fContext.fConfig->isRuntimeEffect();
+        return ProgramConfig::IsRuntimeEffect(fContext.fConfig->fKind);
     }
 
     const ShaderCapsClass& caps() const {
diff --git a/src/sksl/SkSLProgramSettings.h b/src/sksl/SkSLProgramSettings.h
index 4c6bf40..48422da 100644
--- a/src/sksl/SkSLProgramSettings.h
+++ b/src/sksl/SkSLProgramSettings.h
@@ -30,11 +30,10 @@
     bool fForceHighPrecision = false;
     // if true, add -0.5 bias to LOD of all texture lookups
     bool fSharpenTextures = false;
-    // if the program needs to create an RTFlip uniform, this is its offset in the uniform
-    // buffer
+    // if the program needs to create an RTFlip uniform, this is its offset in the uniform buffer
     int fRTFlipOffset = -1;
-    // if the program needs to create an RTFlip uniform and is creating spriv, this is the
-    // binding and set number of the uniform buffer.
+    // if the program needs to create an RTFlip uniform and is creating SPIR-V, this is the binding
+    // and set number of the uniform buffer.
     int fRTFlipBinding = -1;
     int fRTFlipSet = -1;
     // If layout(set=S, binding=B) is not specified for a uniform, these values will be used.
@@ -53,8 +52,8 @@
     int fInlineThreshold = SkSL::kDefaultInlineThreshold;
     // If true, every function in the generated program will be given the `noinline` modifier.
     bool fForceNoInline = false;
-    // If true, implicit conversions to lower precision numeric types are allowed
-    // (eg, float to half)
+    // If true, implicit conversions to lower precision numeric types are allowed (e.g., float to
+    // half). These are always allowed when compiling Runtime Effects.
     bool fAllowNarrowingConversions = false;
     // If true, then Debug code will run SPIR-V output through the validator to ensure its
     // correctness
@@ -91,13 +90,13 @@
 
     bool strictES2Mode() const {
         return fSettings.fEnforceES2Restrictions &&
-               (this->isRuntimeEffect() || fKind == ProgramKind::kGeneric);
+               (IsRuntimeEffect(fKind) || fKind == ProgramKind::kGeneric);
     }
 
-    bool isRuntimeEffect() const {
-        return (fKind == ProgramKind::kRuntimeColorFilter ||
-                fKind == ProgramKind::kRuntimeShader ||
-                fKind == ProgramKind::kRuntimeBlender);
+    static bool IsRuntimeEffect(ProgramKind kind) {
+        return (kind == ProgramKind::kRuntimeColorFilter ||
+                kind == ProgramKind::kRuntimeShader ||
+                kind == ProgramKind::kRuntimeBlender);
     }
 };
 
diff --git a/src/sksl/ir/SkSLFunctionDeclaration.cpp b/src/sksl/ir/SkSLFunctionDeclaration.cpp
index 3554555..845c834 100644
--- a/src/sksl/ir/SkSLFunctionDeclaration.cpp
+++ b/src/sksl/ir/SkSLFunctionDeclaration.cpp
@@ -90,7 +90,7 @@
 
         Modifiers m = param->modifiers();
         if (isMain) {
-            if (context.fConfig->isRuntimeEffect()) {
+            if (ProgramConfig::IsRuntimeEffect(context.fConfig->fKind)) {
                 // We verify that the signature is fully correct later. For now, if this is a
                 // runtime effect of any flavor, a float2 param is supposed to be the coords, and a
                 // half4/float parameter is supposed to be the input or destination color: