SkSL: Allow 'const' on function parameters

Change-Id: I672345116e3b5538c0f7e8c5f2f74aa56bb81e6d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372676
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/resources/sksl/errors/InvalidAssignment.sksl b/resources/sksl/errors/InvalidAssignment.sksl
index fb778af..af58e63 100644
--- a/resources/sksl/errors/InvalidAssignment.sksl
+++ b/resources/sksl/errors/InvalidAssignment.sksl
@@ -17,3 +17,7 @@
 void assign_to_unfoldable_ternary()           { float l, r; (sqrt(1) > 0 ? l : r) = 0; }
 void assign_to_unary_minus()                  { float x; -x = 0; }
 void assign_to_unary_plus()                   { float x; +x = 0; }  // TODO(skbug.com/10766)
+
+void assign_to_const_param(const int x)          { x = 0; }
+void assign_to_const_array_param(const int x[1]) { x[0] = 0; }
+void assign_to_const_struct_param(const S s)     { s.f = 0; }
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 9999f3a..febe77d 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -1158,7 +1158,8 @@
         const ASTNode& param = *(iter++);
         SkASSERT(param.fKind == ASTNode::Kind::kParameter);
         ASTNode::ParameterData pd = param.getParameterData();
-        this->checkModifiers(param.fOffset, pd.fModifiers, Modifiers::kIn_Flag |
+        this->checkModifiers(param.fOffset, pd.fModifiers, Modifiers::kConst_Flag |
+                                                           Modifiers::kIn_Flag |
                                                            Modifiers::kOut_Flag);
         auto paramIter = param.begin();
         const Type* type = this->convertType(*(paramIter++));
diff --git a/tests/sksl/errors/BadModifiers.glsl b/tests/sksl/errors/BadModifiers.glsl
index 76aeaad..05f5fe9 100644
--- a/tests/sksl/errors/BadModifiers.glsl
+++ b/tests/sksl/errors/BadModifiers.glsl
@@ -7,7 +7,6 @@
 error: 1: 'flat' is not permitted here
 error: 1: 'noperspective' is not permitted here
 error: 1: 'varying' is not permitted here
-error: 3: 'const' is not permitted here
 error: 3: 'uniform' is not permitted here
 error: 3: 'flat' is not permitted here
 error: 3: 'noperspective' is not permitted here
@@ -18,4 +17,4 @@
 error: 5: 'varying' is only permitted in runtime effects
 error: 5: 'sk_has_side_effects' is not permitted here
 error: 5: 'inline' is not permitted here
-18 errors
+17 errors
diff --git a/tests/sksl/errors/InvalidAssignment.glsl b/tests/sksl/errors/InvalidAssignment.glsl
index 7ccc04b..865e758 100644
--- a/tests/sksl/errors/InvalidAssignment.glsl
+++ b/tests/sksl/errors/InvalidAssignment.glsl
@@ -12,4 +12,7 @@
 error: 16: cannot modify immutable variable 'l'
 error: 17: cannot assign to this expression
 error: 18: cannot assign to this expression
-12 errors
+error: 21: cannot modify immutable variable 'x'
+error: 22: cannot modify immutable variable 'x'
+error: 23: cannot modify immutable variable 's'
+15 errors