e3ae968f5f
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>
39 lines
1.2 KiB
Metal
39 lines
1.2 KiB
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Uniforms {
|
|
float4 colorGreen;
|
|
float4 colorRed;
|
|
};
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_FragColor [[color(0)]];
|
|
};
|
|
|
|
template <typename T1, typename T2, size_t N>
|
|
bool operator==(thread const array<T1, N>& left, thread const array<T2, N>& right) {
|
|
for (size_t index = 0; index < N; ++index) {
|
|
if (!(left[index] == right[index])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
template <typename T1, typename T2, size_t N>
|
|
bool operator!=(thread const array<T1, N>& left, thread const array<T2, N>& right) {
|
|
return !(left == right);
|
|
}
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
|
Outputs _out;
|
|
(void)_out;
|
|
array<int, 2> i2 = array<int, 2>{1, 2};
|
|
array<short, 2> s2 = array<short, 2>{1, 2};
|
|
array<float, 2> f2 = array<float, 2>{1.0, 2.0};
|
|
array<float, 2> h2 = array<float, 2>{1.0, 2.0};
|
|
const array<float, 2> cf2 = array<float, 2>{1.0, 2.0};
|
|
_out.sk_FragColor = ((i2 == s2 && f2 == h2) && i2 == array<int, 2>{1, 2}) && h2 == cf2 ? _uniforms.colorGreen : _uniforms.colorRed;
|
|
return _out;
|
|
}
|