skia2/resources/sksl/shared/ArrayNarrowingConversions.sksl
John Stiles e3ae968f5f Enable comparison of arrays of different precision types.
GLSL allows an array of `lowp float` to be compared against `highp
float` seamlessly because the types are considered to be the same. SkSL,
however, treats these as different types, so we need to coerce the types
to allow this comparison to work.

In other words, these comparisons can cause an array to be implicitly
casted. The expression `myHalf2Array == float[2](a, b)` should be
allowed when narrowing conversions are enabled. To allow this to work,
we need a dedicated IR node representing this type coercion.

We now allow implicit coercion of array types when the array's component
types would be implicitly coercible, and have a new IR node representing
that implicit conversion.

This CL fixes array comparisons, but array assignment needs additional
fixes. It currently results in:
    "type mismatch: '=' cannot operate on (types)".

Bug: skia:12248
Change-Id: I99062486c081f748f65be4b36a3a52e95b559812
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/436571
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-08-06 12:57:10 +00:00

20 lines
556 B
Plaintext

/*#pragma settings AllowNarrowingConversions*/
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
int i2[2] = int[2](1, 2);
short s2[2] = short[2](1, 2);
float f2[2] = float[2](1, 2);
half h2[2] = half[2](1, 2);
const int ci2[2] = int[2](1, 2);
const short cs2[2] = short[2](1, 2);
const float cf2[2] = float[2](1, 2);
const half ch2[2] = half[2](1, 2);
return (i2 == s2 && f2 == h2 && ci2 == cs2 && cf2 == ch2 && i2 == cs2 && h2 == cf2)
? colorGreen
: colorRed;
}