Disallow samplers as ternary operands
Quoting the ESSL 1.00 spec section 4.1.7: "Except for parameters to
texture lookup functions, array indexing, structure field selection,
and parentheses, samplers are not allowed to be operands in
expressions."
ESSL 3.00 has a similar passage related to opaque types.
Validate this correctly. Compatibility risk should be low, since
attempting to use samplers in ternary operators was already failing
before this in most cases.
BUG=angleproject:1551
TEST=angle_unittests
Change-Id: I6cbb536f473ba9674d558b14a458f3799f9c7c9c
Reviewed-on: https://chromium-review.googlesource.com/402694
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 96785cf..fc5ea60 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -4321,6 +4321,17 @@
falseExpression->getCompleteString());
return falseExpression;
}
+ if (IsOpaqueType(trueExpression->getBasicType()))
+ {
+ // ESSL 1.00 section 4.1.7
+ // ESSL 3.00 section 4.1.7
+ // Opaque/sampler types are not allowed in most types of expressions, including ternary.
+ // Note that structs containing opaque types don't need to be checked as structs are
+ // forbidden below.
+ error(loc, "ternary operator is not allowed for opaque types", ":");
+ return falseExpression;
+ }
+
// ESSL1 sections 5.2 and 5.7:
// ESSL3 section 5.7:
// Ternary operator is not among the operators allowed for structures/arrays.