From 2fe67f96803e5e7caf845f9ad3e3a3af76b68411 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 17 Feb 2021 16:24:04 -0500 Subject: [PATCH] Disallow initializers on uniform variables Bug: skia:11335 Change-Id: I88c952cbfe2d2c5920e17675da1674928f37b982 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371480 Reviewed-by: John Stiles Commit-Queue: Brian Osman --- gn/sksl_tests.gni | 1 + resources/sksl/errors/SwitchTypes.sksl | 4 ++-- .../sksl/errors/UniformVarWithInitializerExpression.sksl | 3 +++ src/sksl/SkSLIRGenerator.cpp | 4 ++++ tests/sksl/errors/UniformVarWithInitializerExpression.glsl | 5 +++++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 resources/sksl/errors/UniformVarWithInitializerExpression.sksl create mode 100644 tests/sksl/errors/UniformVarWithInitializerExpression.glsl diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index 470df5c25a..3c5b735245 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -175,6 +175,7 @@ sksl_error_tests = [ "/sksl/errors/UndeclaredFunction.sksl", "/sksl/errors/UndefinedFunction.sksl", "/sksl/errors/UndefinedSymbol.sksl", + "/sksl/errors/UniformVarWithInitializerExpression.sksl", "/sksl/errors/UnknownDivideByZero.sksl", "/sksl/errors/Unreachable.sksl", "/sksl/errors/UnsupportedGLSLIdentifiers.sksl", diff --git a/resources/sksl/errors/SwitchTypes.sksl b/resources/sksl/errors/SwitchTypes.sksl index 7b4d47ab14..911f8dbe18 100644 --- a/resources/sksl/errors/SwitchTypes.sksl +++ b/resources/sksl/errors/SwitchTypes.sksl @@ -1,5 +1,5 @@ -uniform float uf = 1; -uniform int ui = 1; +uniform float uf; +uniform int ui; const float cf = 1; const int ci = 1; int i = 1; diff --git a/resources/sksl/errors/UniformVarWithInitializerExpression.sksl b/resources/sksl/errors/UniformVarWithInitializerExpression.sksl new file mode 100644 index 0000000000..eee874246f --- /dev/null +++ b/resources/sksl/errors/UniformVarWithInitializerExpression.sksl @@ -0,0 +1,3 @@ +uniform float x = 1; +float y; +uniform float z = y = 1; diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 17c05c5ff6..1c016bcc1f 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -472,6 +472,10 @@ std::unique_ptr IRGenerator::convertVarDeclaration(int offset, this->errorReporter().error(value->fOffset, "'in' variables cannot use initializer expressions"); } + if (modifiers.fFlags & Modifiers::kUniform_Flag) { + this->errorReporter().error(value->fOffset, + "'uniform' variables cannot use initializer expressions"); + } value = this->coerce(std::move(value), *type); if (!value) { return {}; diff --git a/tests/sksl/errors/UniformVarWithInitializerExpression.glsl b/tests/sksl/errors/UniformVarWithInitializerExpression.glsl new file mode 100644 index 0000000000..b9697ae23f --- /dev/null +++ b/tests/sksl/errors/UniformVarWithInitializerExpression.glsl @@ -0,0 +1,5 @@ +### Compilation failed: + +error: 1: 'uniform' variables cannot use initializer expressions +error: 3: 'uniform' variables cannot use initializer expressions +2 errors