skia2/tests/sksl/shared/golden/Assignment.metal
John Stiles dc75a97b80 Add global struct definitions to SkSL.
Previously, GLSL and Metal code generators would emit a struct wherever
the type was first used in the code, regardless of where it was
originally defined or what scope the type needs to live in. This CL adds
a ProgramElement for struct definitions, so that structs will now appear
at the top-level as they were originally defined. In the case of Metal,
some special handling is also needed to handle the Globals struct
properly.

Not yet fully supported:
- No special handling for structs declared inside functions yet
- No support for structs in separate scopes with overlapping names
The severity of the remaining issues depends mostly on whether we want
to support structs inside functions in Runtime Effects.

Change-Id: Ia95d4529506cb3fa6da63f5cb548199a93e1c0c5
Bug: skia:10922, skia:10923, skia:10925, skia:10926
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338600
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-11-30 15:26:14 +00:00

56 lines
1.5 KiB
Metal

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct S {
float f;
float af[5];
float4 h4;
float4 ah4[5];
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
float4 x;
x.w = 0.0;
x.yx = float2(0.0);
int ai[1];
ai[0] = 0;
int4 ai4[1];
ai4[0] = int4(1, 2, 3, 4);
float2x4 ah2x4[1];
ah2x4[0] = float2x4(float4(1.0, 2.0, 3.0, 4.0), float4(5.0, 6.0, 7.0, 8.0));
ai[0] = 0;
ai[ai[0]] = 0;
float4 af4[1];
af4[0].x = 0.0;
af4[0].ywxz = float4(1.0);
S s;
s.f = 0.0;
s.af[1] = 0.0;
s.h4.zxy = float3(9.0);
s.ah4[2].yw = float2(5.0);
s.f = 1.0;
s.af[0] = 2.0;
s.h4 = float4(1.0);
s.ah4[0] = float4(2.0);
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(int4(1, 2, 3, 4));
_out->sk_FragColor = float3x3(float3(1.0, 2.0, 3.0), float3(4.0, 5.0, 6.0), float3(7.0, 8.0, 9.0))[0].xxyz;
_out->sk_FragColor = x;
_out->sk_FragColor = float4(float(ai[0]));
_out->sk_FragColor = float4(ai4[0]);
_out->sk_FragColor = ah2x4[0][0];
_out->sk_FragColor = af4[0];
_out->sk_FragColor = float4(0.0);
_out->sk_FragColor = float4(s.f);
_out->sk_FragColor = float4(s.af[1]);
_out->sk_FragColor = s.h4;
_out->sk_FragColor = s.ah4[0];
return *_out;
}