skia2/resources/sksl/shared/Assignment.sksl
John Stiles dd904af566 Improve support for arrays in Metal.
Arrays in Metal now use the `array<T, N>` type instead of the C-style
`T[N]` type. This gives them semantics much more in line with GLSL,
so they can be initialized and assigned like GLSL arrays.

This allows the ArrayTypes and Assignment tests to pass, so they have
been added to our dm SkSL tests. (ArrayConstructors also passes, but
is not ES2-compliant so it is not enabled.)

Change-Id: Id1028311963084befd0e044e11e223af6a064dda
Bug: skia:10761, skia:10760, skia:11022, skia:10939
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/365699
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-03 22:33:19 +00:00

40 lines
1.6 KiB
Plaintext

uniform half4 colorGreen;
// TODO(skia:10939): Structs not working in Runtime Effects yet
//struct S {
// float f;
// float af[5];
// half4 h4;
// half4 ah4[5];
//};
half4 main() {
/* assign to scalar */ int i; i = 0;
/* assign to vector */ int4 i4; i4 = int4(1,2,3,4);
/* assign to matrix */ float3x3 f3x3; f3x3 = float3x3(1,2,3,4,5,6,7,8,9);
/* assign to swizzle */ half4 x; x.w = 0; x.yx = half2(0);
/* assign to array of scalar */ int ai[1]; ai[0] = 0;
/* assign to array of vector */ int4 ai4[1]; ai4[0] = int4(1,2,3,4);
/* assign to array of matrix */ half3x3 ah2x4[1]; ah2x4[0] = half3x3(1,2,3,4,5,6,7,8,9);
/* assign to array swizzle */ float4 af4[1]; af4[0].x = 0; af4[0].ywxz = float4(1);
// TODO(skia:10939): Structs not working in Runtime Effects yet
// /* assign to struct variable */ S s; s.f = 0;
// /* assign to struct array */ s.af[1] = 0;
// /* assign to struct swizzle */ s.h4.zxy = half3(9);
// /* assign to struct array swizzle */ s.ah4[2].yw = half2(5);
// Not allowed in ES2
// /* assign to array idx by lookup */ ai[0] = 0; ai[ai[0]] = 0;
// Not allowed natively in GLSL, but SkSL will turn these into valid GLSL expressions.
/* assign to folded ternary */ half l, r; (true ? l : r) = 0;
// TODO(skia:10939): Structs not working in Runtime Effects yet
// /* assign to struct unary plus */ +s.f = 1; +s.af[0] = 2;
// +s.h4 = half4(1); +s.ah4[0] = half4(2);
i4.y *= i;
x.y *= l;
return ai, ai4, ah2x4, af4, colorGreen;
}