Store float value for settings in SkSL v2

If you used 'in float foo' in a runtime effect it would always have the
value cast to an int. I don't think we saw this in .fp files because
the cpp generation handled those values directly (if I remember correctly)

Just uses a union of float and int, differentiated by fKind, so that it
compiles in standalone mode (vs. using SkFloat2Bits, etc.).

Also updated to add a unit test.

Change-Id: I420f43d1b54638883af0b8df6ccba2416c587868
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292315
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h
index c7694b5..ed15866 100644
--- a/src/sksl/ir/SkSLProgram.h
+++ b/src/sksl/ir/SkSLProgram.h
@@ -53,7 +53,7 @@
 
             Value(float f)
             : fKind(kFloat_Kind)
-            , fValue(f) {}
+            , fValueF(f) {}
 
             std::unique_ptr<Expression> literal(const Context& context, int offset) const {
                 switch (fKind) {
@@ -67,8 +67,8 @@
                                                                           fValue));
                     case Program::Settings::Value::kFloat_Kind:
                         return std::unique_ptr<Expression>(new FloatLiteral(context,
-                                                                          offset,
-                                                                          fValue));
+                                                                            offset,
+                                                                            fValueF));
                     default:
                         SkASSERT(false);
                         return nullptr;
@@ -81,7 +81,10 @@
                 kFloat_Kind,
             } fKind;
 
-            int fValue;
+            union {
+                int   fValue;  // for kBool_Kind and kInt_Kind
+                float fValueF; // for kFloat_Kind
+            };
         };
 
 #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index d28b3e4..66dacd3 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -146,6 +146,10 @@
     pickColor.test(r, surface, 0x7F00007F);  // Tests that we clamp to valid premul
     pickColor["flag"] = 1;
     pickColor.test(r, surface, 0xFF00FF00);
+
+    TestEffect inlineColor(r, "in half c;", "color = half4(c, c, c, 1);");
+    inlineColor["c"] = 0.498f;
+    inlineColor.test(r, surface, 0xFF7F7F7F);
 }
 
 DEF_TEST(SkRuntimeEffectSimple, r) {