830c69ca66
GLSL/SkSL assumes that == and != on struct/array types should work. We need to emit equality and inequality operators whenever we find code that compares a struct or array. Structs and arrays can be arbitrarily nested, and either type can contain a matrix. All of these things need custom equality operators in Metal. Therefore, we need to recursively generate comparison operators when any of these types are encountered. For arrays we get lucky, and we can cover all possible array types and sizes with a single templated operator== method. Structs and matrices have no such luck, and are generated separately on a per-type basis. For each of these types, operator== is implemented as an equality check on each field, and operator!= is implemented in terms of operator==. Equality and inequality are always emitted together. (Previously, matrix equality and inequality were emitted and implemented independently, but this is no longer the case.) Change-Id: I69ee01c0a390d7db6bcb2253ed6336ab20cc4d1d Bug: skia:11908, skia:11924 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402016 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
34 lines
1.2 KiB
Metal
34 lines
1.2 KiB
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Uniforms {
|
|
float4x4 colorXform;
|
|
};
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_FragColor [[color(0)]];
|
|
};
|
|
struct Globals {
|
|
texture2d<float> s;
|
|
sampler sSmplr;
|
|
};
|
|
thread bool operator==(const float4x4 left, const float4x4 right) {
|
|
return all(left[0] == right[0]) &&
|
|
all(left[1] == right[1]) &&
|
|
all(left[2] == right[2]) &&
|
|
all(left[3] == right[3]);
|
|
}
|
|
thread bool operator!=(const float4x4 left, const float4x4 right) {
|
|
return !(left == right);
|
|
}
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], texture2d<float> s[[texture(0)]], sampler sSmplr[[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
|
Globals _globals{s, sSmplr};
|
|
(void)_globals;
|
|
Outputs _out;
|
|
(void)_out;
|
|
float4 tmpColor;
|
|
_out.sk_FragColor = (tmpColor = _globals.s.sample(_globals.sSmplr, float2(1.0)) , _uniforms.colorXform != float4x4(1.0) ? float4(clamp((_uniforms.colorXform * float4(tmpColor.xyz, 1.0)).xyz, 0.0, tmpColor.w), tmpColor.w) : tmpColor);
|
|
return _out;
|
|
}
|